Skip to content

Conversation

@smiecielica-billtech
Copy link
Collaborator

Aktualnie w tabeli billtech_customer_info przetrzymujemy pary customer_id | last_cash_id. Niestety ten last_cash_id nie odpowiada realnie rekordowi cash danego użytkownika, tylko najwyższego id na całej tabeli cash w momencie wykonania ostatniej aktualizacji.
Ułatwi to trakowanie aktualizacji u danego usera, bo będzie jasno widać, który cash był ostatni aktualizowany przez wtyczkę i dodatkowo w przypadku ręcznych usuwań (na przykład faktura jest opłacona, ale rekord wpłaty zostaje jednak usunięty ręcznie przez dostawcę) wracamy z cash_id do poprzedniej faktury i dokonujemy przeliczenia (bo wykrywane jest i przeliczany jest bilans).

* @return bool
*/
private function checkIfCustomerCashIdExists(integer $customerId, integer $cashId): bool
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format

Copy link
Contributor

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ę.

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']))) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Postarałbym się oddzielić SQL od PHP. Chociaż poprzez formatowanie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants