/** * * * * @return int total invoice paid */ public function calculateInvoicetotalPaid($invoice_id) { $paymentItem = LbPaymentItem::model()->findAll('lb_invoice_id = ' . intval($invoice_id)); $total_paid = 0; foreach ($paymentItem as $data) { $total_paid += $data->lb_payment_item_amount; } $this->lb_invoice_total_paid = $total_paid; $this->save(); return $this->lb_invoice_total_paid; }
<?php $PaymentInvoice = LbPaymentItem::model()->getAllPaymentByInvoice($invoice_id); $method = LBPayment::model()->method; if ($invoice_status != LbInvoice::LB_INVOICE_STATUS_CODE_DRAFT) { $grid_payment_id = 'invoice-line-payment-grid-' . $invoice_id; $this->widget('bootstrap.widgets.TbGridView', array('id' => $grid_payment_id, 'type' => 'bordered', 'dataProvider' => $PaymentInvoice, 'columns' => array(array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => "{delete}", 'deleteButtonUrl' => '"' . LbInvoice::model()->getActionURLNormalized("ajaxDeletePayment") . '" . "?id={$data->lb_record_primary_key}&invoice_id={$data->lb_invoice_id}"', 'afterDelete' => 'function(link,success,data){ if(success) { var responseJSON = $.parseJSON(data); var status = responseJSON.status; if(status == "I_PAID") { $("#lb_invocie_status").text("Paid"); } else $("#lb_invocie_status").text("Open"); $("#invoice-outstanding-' . $invoice_id . '").text(responseJSON.outstanding); $("#invoice-paid-' . $invoice_id . '").text(responseJSON.paid); } } ', 'htmlOptions' => array('style' => 'width: 10px'), 'headerHtmlOptions' => array('class' => 'lb-grid-header')), array('header' => Yii::t('lang', 'Payment No'), 'type' => 'raw', 'value' => 'LbPayment::model()->getPaymentById($data->lb_payment_id)->lb_payment_no ', 'htmlOptions' => array('width' => '100', 'style' => 'text-align: right;'), 'headerHtmlOptions' => array('class' => 'lb-grid-header')), array('header' => Yii::t('lang', 'Payment Date'), 'type' => 'raw', 'value' => ' CHtml::activeTextField(LbPayment::model()->getPaymentById($data->lb_payment_id),"lb_payment_date", array("style"=>"width: 100px;text-align: right; padding-right: 0px; border-top: none; border-left: none; border-right: none; box-shadow: none;", "class"=>"lbinvoice-line-payment_date", "name"=>"lb_invoice_item_payment_{$data->lb_record_primary_key}",
echo '<div class="invoice-total-container" style="margin-top: -20px ;margin-bottom:30px;border-left:solid 1px #dddddd;border-right:solid 1px #dddddd; border-bottom:solid 1px #dddddd;border-right:solid 1px #dddddd;" >'; // total after tax echo '<div class="invoice-total-label" style="margin-left:236px;">' . Yii::t('lang', 'Total') . ' (' . $currency_name . '):</div>'; echo "<div id='invoice-total-{$model->lb_record_primary_key}' class='invoice-total-value'>"; echo number_format($invoiceTotal->lb_invoice_total_after_taxes, 2, $lb_decimal_symbol, $lb_thousand_separator); echo '</div>'; // paid echo '<div class="invoice-total-label" style="margin-left:236px;">' . Yii::t('lang', 'Paid') . ' (' . $currency_name . '):</div>'; echo "<div id='invoice-paid-{$model->lb_record_primary_key}' class='invoice-total-value'>" . number_format($invoiceTotal->calculateInvoicetotalPaid($model->lb_record_primary_key), 2, $lb_decimal_symbol, $lb_thousand_separator) . "</div>"; // outstanding echo '<div style="margin-left:236px;" class="invoice-total-label">' . Yii::t('lang', 'Outstanding') . ' (' . $currency_name . '):</div>'; echo "<div id='invoice-outstanding-{$model->lb_record_primary_key}' class='invoice-total-value'>" . number_format($invoiceTotal->calculateInvoiceTotalOutstanding(), 2, $lb_decimal_symbol, $lb_thousand_separator) . "</div>"; echo '</div>'; echo '</div>'; //Payment $PaymentInvoice = LbPaymentItem::model()->getAllPaymentByInvoice($model->lb_record_primary_key); echo '<div id="container-invoice-line-items-section" style="margin-top: 30px;clear:both;">'; $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'lb-invoice-items-form', 'enableAjaxValidation' => false, 'type' => 'horizontal')); /** LineItem Grid's $data is LbInvoiceItem Each line item's fields (description, quantity, unit price and total) are marked by the line item's primary key. */ //$modelPayment = LBPayment::model()->getPaymentById($PaymentInvoice); //$this->widget('ext.rezvan.RDatePicker',array( // 'name'=>'message[messageDate]', // 'value'=>$modelPayment->lb_payment_date, // 'options' => array( // 'format' => 'yyyy/mm/dd', // 'viewformat' => 'yyyy/mm/dd', // 'placement' => 'right',
function actionajaxDeletePayment() { if (isset($_GET['id'])) { $payment_item_id = $_GET['id']; } //delete payment item $payment = LbPaymentItem::model()->deleteByPk($payment_item_id); $invoice_id = $_GET['invoice_id']; $invoiceTotal = LbInvoiceTotal::model()->getInvoiceTotal($invoice_id); $taxRecord['paid'] = $invoiceTotal->calculateInvoicetotalPaid($invoice_id); $taxRecord['outstanding'] = $invoiceTotal->calculateInvoiceTotalOutstanding(); if ($invoiceTotal->calculateInvoiceTotalOutstanding() <= 0) { $taxRecord['status'] = 'I_PAID'; } else { $taxRecord['status'] = 'Open'; } //update invoice total // if($payment->delete()) // echo 'success'; LBApplication::renderPlain($this, array('content' => CJSON::encode($taxRecord))); }
if ($YStart == $YEnd && $MStart == $MEnd) { $PaymentAll = LbPayment::model()->getAllPayment($FromDate, $Todate, $customer_id, false, false, $i); } else { $PaymentAll = LbPayment::model()->getAllPayment($FromDate, $numberDate, $customer_id, false, false, $i); } if (count($PaymentAll) > 0) { $paymentAmount = 0; foreach ($PaymentAll as $data) { if (LbCustomer::model()->isCustomer($data->attributes['lb_payment_customer_id']) != null) { $customer_information = LbCustomer::model()->find('lb_record_primary_key=' . intval($data->attributes['lb_payment_customer_id'])); $customer_name = $customer_information->lb_customer_name; echo '<tr>'; echo '<td>' . $data->attributes['lb_payment_date'] . '</td>'; echo '<td>' . $customer_name . '</td>'; echo '<td>' . $data->attributes['lb_payment_notes'] . '</td>'; $payment_item = LbPaymentItem::model()->getAllPaymentInvoice($data->lb_record_primary_key); echo '<td>'; foreach ($payment_item as $payment) { // echo $payment->lb_invoice_id; $invoiceNo = LbInvoice::model()->find('lb_record_primary_key=' . intval($payment->lb_invoice_id)); if (isset($invoiceNo->lb_record_primary_key)) { echo $invoiceNo->lb_invoice_no . ':$' . $payment->lb_payment_item_amount . '; '; $paymentAmount = $paymentAmount + $payment->lb_payment_item_amount; $AmountMonth = $AmountMonth + $payment->lb_payment_item_amount; } } echo '</td>'; $total = $total + $data->attributes['lb_payment_total']; echo '<td>' . $data->attributes['lb_payment_total'] . '</td>'; echo '</tr>'; }
echo Yii::t('lang', 'Method'); ?> </th> <th width="150" class="lb-grid-header"><?php echo Yii::t('lang', 'Date'); ?> </th> <th class="lb-grid-header"><?php echo Yii::t('lang', 'Notes'); ?> </th> </tr> </thead> <tbody> <?php $paymentItem = LbPaymentItem::model()->findAll('lb_invoice_id=' . intval($data_invocie->lb_record_primary_key)); foreach ($paymentItem as $data_paymentItem) { $payment = LbPayment::model()->findByPk(intval($data_paymentItem->lb_payment_id)); ?> <tr> <td style="text-align: right"><?php echo number_format($data_paymentItem->lb_payment_item_amount, 2); ?> </td> <td style="text-align: center"><?php echo $method[$payment->lb_payment_method]; ?> </td> <td style="text-align: center"><?php echo $payment->lb_payment_date; ?>
</td> </tr> </table> </td> </tr></table></td></tr>'; $a .= '<tr><td> <table border="1" style="width:90%;margin-top:10px;" cellpadding="0" cellspacing="0"> <tr style="background-color:#ddd"> <td style="width:20%;height:30px;">Receipt Nos</td> <td height="40" style="width:20%">Amount Paid</td> <td style="text-align:center;width:20%">Method</td> <td style="width:20%">Data</td> <td style="width:20%">Notes</td> </tr>'; $data_paymentItem = LbPaymentItem::model()->findAll('lb_invoice_id=:invoice_id', array(':invoice_id' => $model->lb_record_primary_key)); foreach ($data_paymentItem as $payment_invoice) { $payment = LbPayment::model()->findByPk($payment_invoice->lb_payment_id); $a .= '<tr> <td class="lb-grid" style="text-align: center">' . $payment->lb_payment_no . '</td> <td class="lb-grid" style="text-align: right;">' . $strnum->adddotstring($payment_invoice->lb_payment_item_amount, $thousand, $decimal) . '</td>'; if (isset($payment)) { $a .= ' <td class="lb-grid" style="text-align: center">' . $method[$payment->lb_payment_method] . '</td> <td style="text-align: center">' . date('d-M-Y', strtotime($payment->lb_payment_date)) . '</td> <td width="200px">' . $payment_invoice->lb_payment_item_note . '</td>'; } $a .= '</tr>'; } $a .= '<tr> <td height="20" style="text-align: left;color: #6E8900;float:right;"><span style="float: left;text-align: left;">Total Paid: </span>$' . $strnum->adddotstring($invoice_total->lb_invoice_total_paid, $thousand, $decimal) . '</td>
public function getAllPaymentInvoice($lb_payment_id = false) { $criteria = new CDbCriteria(); $criteria->condition = "lb_payment_id = {$lb_payment_id}"; return LbPaymentItem::model()->findAll($criteria); }