public function submit() { if ($this->prepare()) { $voucher = TransactionProcessor::ProcessPayment($this); if ($voucher) { //payment has gone trough; $supplier = Supplier::GetSupplier($this->supplierId); $grns = PurchaseInvoice::GetUnclearedInvoices($this->supplierId); if ($supplier->balance->amount > 0) { $amount = $this->amount->amount; } else { //if supplier has a prepayment (-ve ba) $amount = $this->amount->amount - $supplier->balance->amount; } $paidamt = floatval(0.0); $credgrn = ''; foreach ($grns as $grn) { if ($amount - $paidamt >= $grn->balance->amount) { $paidamt = $paidamt + $grn->balance->amount; $grn->credit(floatval($grn->balance->amount)); $credgrn .= $grn->id . ','; } elseif ($amount - $paidamt < $grn->balance->amount && $amount - $paidamt > 0.0) { $grn->credit(floatval($amount - $paidamt)); $credgrn .= $grn->id . ','; $paidamt = $paidamt + ($amount - $paidamt); } elseif ($amount == $paidamt) { break; } } $this->status = 1; $this->updateParticulars($credgrn); return $voucher; } else { return false; } } //make the journal entry based on the invoicing TX //Cr - Sales //Dr - Debtors [A/C Receivable] //Dr - Taxes Collectable }
public function getUnclearedInvoices($supplierid) { if ($this->validateAdmin()) { echo json_encode(PurchaseInvoice::GetUnclearedInvoices($supplierid)); } else { echo 0; } }