-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zmiana wartości last_cash_id dla billtech_customer_info #82
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,6 @@ public function getBalanceLink($customerId, $params) | |
|
||
public function updateForAll() | ||
{ | ||
global $DB; | ||
$actions = array( | ||
'add' => array(), | ||
'update' => array(), | ||
|
@@ -85,8 +84,6 @@ public function updateForAll() | |
return; | ||
} | ||
|
||
$maxCashId = $DB->GetOne("select max(id) from cash"); | ||
|
||
foreach ($customerIds as $idx => $customerId) { | ||
echo "Collecting actions for customer " . ($idx + 1) . " of " . count($customerIds) . "\n"; | ||
$actions = array_merge_recursive($actions, $this->getCustomerUpdateBalanceActions($customerId)); | ||
|
@@ -99,11 +96,25 @@ public function updateForAll() | |
} | ||
|
||
if ($this->performActions($actions)) { | ||
$this->updateCustomerInfos($customerIds, $maxCashId); | ||
$this->updateCustomerInfos($customerIds); | ||
} | ||
} | ||
|
||
public function updateCustomerBalance($customerId) | ||
/** | ||
* @param $customerId integer | ||
* @param $cashId integer | ||
* @return bool | ||
*/ | ||
private function checkIfCustomerCashIdExists(integer $customerId, integer $cashId): bool | ||
{ | ||
global $DB; | ||
return $DB->GetOne('select count(*) from cash where customerid = ? and id = ?', array($customerId, $cashId)); | ||
} | ||
|
||
/** | ||
* @var $customerId integer | ||
*/ | ||
public function updateCustomerBalance(integer $customerId) | ||
{ | ||
global $DB; | ||
$this->addMissingCustomerInfo(); | ||
|
@@ -113,7 +124,7 @@ public function updateCustomerBalance($customerId) | |
where bci.customer_id = ? | ||
group by bci.customer_id", array($customerId)); | ||
|
||
if ($customerInfo['new_last_cash_id'] > $customerInfo['last_cash_id']) { | ||
if ($customerInfo['new_last_cash_id'] > $customerInfo['last_cash_id'] || ($customerInfo['new_last_cash_id'] < $customerInfo['last_cash_id'] && !$this->checkIfCustomerCashIdExists($customerId, $customerInfo['last_cash_id']))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trzeba trochę poprawiać ten kod. Dałbym te warunki pod funkcje pomocnicze o odpowiednich nazwach. |
||
$actions = $this->getCustomerUpdateBalanceActions($customerId); | ||
if ($this->performActions($actions)) { | ||
$DB->Execute("update billtech_customer_info set last_cash_id = ? where customer_id = ?", array($customerInfo['new_last_cash_id'], $customerId)); | ||
|
@@ -410,19 +421,18 @@ private function getCustomerIdsForUpdate() | |
left join billtech_customer_info bci on bci.customer_id = cu.id | ||
left join cash ca on ca.customerid = cu.id | ||
group by bci.customer_id, bci.last_cash_id | ||
having bci.last_cash_id <= coalesce(max(ca.id), 0);"); | ||
having bci.last_cash_id != coalesce(max(ca.id), 0);")?: array(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Postarałbym się oddzielić SQL od PHP. Chociaż poprzez formatowanie. |
||
} | ||
|
||
/** | ||
* @param array $customerIds | ||
* @param $maxCashId | ||
*/ | ||
private function updateCustomerInfos(array $customerIds, $maxCashId) | ||
private function updateCustomerInfos(array $customerIds) | ||
{ | ||
global $DB; | ||
$params = $customerIds; | ||
array_unshift($params, $maxCashId); | ||
$DB->Execute("update billtech_customer_info set last_cash_id = ? where customer_id in (" . BillTech::repeatWithSeparator("?", ",", count($customerIds)) . ")", $params); | ||
$DB->Execute("update billtech_customer_info bci | ||
set last_cash_id = (select max(c.id) from cash c where c.customerid = bci.customer_id) | ||
where customer_id in (".implode(',', $customerIds).");"); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ta funkcja nie zwraca bool. Dodałbym castowanie albo poprawił sygnaturę.