Esempio n. 1
0
 function actionAjaxSavePayment()
 {
     $model = new LbPayment();
     if (isset($_POST['LbPayment'])) {
         $payment_arr = $_POST['LbPayment'];
         $payment_arr = $_POST['LbPayment'];
         $model->lb_payment_no = LbPayment::model()->FormatPaymentNo(LbPayment::model()->getPaymentNextNum());
         $model->lb_payment_customer_id = $_POST['customer_id'];
         $model->lb_payment_method = $payment_arr['lb_payment_method'];
         $model->lb_payment_date = $payment_arr['lb_payment_date'];
         //$model->lb_payment_notes=$payment_arr['lb_payment_notes'];
         $model->lb_payment_total = $_POST['total_payment'];
         //$model->lb_invoice_id = $_POST[]
         if ($model->save()) {
             //LbPayment::model()->setPaymentNextNum();
             // save payment item
             $count_payment = count($_POST['payment_check']);
             $payment_invoice = $_POST['payment_check'];
             $payment_note = $_POST['payment_note'];
             $payment_item_amount = $_POST['payment'];
             for ($i = 0; $i < $count_payment; $i++) {
                 if ($payment_item_amount[$i] > 0) {
                     $paymentItemModel = new LbPaymentItem();
                     $paymentItemModel->lb_payment_id = $model->lb_record_primary_key;
                     $paymentItemModel->lb_invoice_id = $payment_invoice[$i];
                     $paymentItemModel->lb_payment_item_note = $payment_note[$i];
                     $paymentItemModel->lb_payment_item_amount = $payment_item_amount[$i];
                     if ($paymentItemModel->save()) {
                         $invoice_total = LbInvoiceTotal::model()->getInvoiceTotal($paymentItemModel->lb_invoice_id);
                         if ($invoice_total) {
                             $invoice_total->calculateInvoicetotalPaid($paymentItemModel->lb_invoice_id);
                             $total_outstanding = $invoice_total->calculateInvoiceTotalOutstanding();
                             if (isset($total_outstanding)) {
                                 //Update Status
                                 LbInvoice::model()->InvoiceUpdateStatus($payment_invoice[$i]);
                             }
                         }
                         echo '{"status":"success"}';
                     } else {
                         echo '{"status":"fail"}';
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
 public function getInvoiceById($invoice_id = false)
 {
     $criteria = new CDbCriteria();
     if ($invoice_id) {
         $criteria->compare('lb_invoice_id', $invoice_id);
     }
     return LbInvoiceTotal::model()->find($criteria);
 }
                        
                    </tfoot>
  
                    <?php 
} else {
    $customer_arr = LbCustomer::model()->getCompanies($sort = 'lb_customer_name ASC', LbCustomer::LB_QUERY_RETURN_TYPE_MODELS_ARRAY);
    $invoiceValue = 0;
    $gst = 0;
    foreach ($customer_arr as $customer) {
        ?>
                            <tbody>
                            <?php 
        $a = LbInvoice::model()->getInvoiceMonth($customer['lb_record_primary_key'], $date_from, $date_to);
        foreach ($a as $data) {
            $customer_id = false;
            $invoice_information = LbInvoiceTotal::model()->getInvoiceById($data->lb_record_primary_key);
            $invoiceTax = LbInvoiceItem::model()->getInvoiceTaxById($data->lb_record_primary_key, "TAX");
            $invoiceValue = $invoiceValue + $invoice_information->lb_invoice_total_after_discounts;
            echo '<tr>';
            echo '<td>' . $data->lb_invoice_no . '</td>';
            echo '<td>' . $data->lb_invoice_date . '</td>';
            echo '<td>';
            if ($data->lb_invoice_customer_id) {
                $customer_id = $data->lb_invoice_customer_id;
                echo LbCustomer::model()->customerInformation($customer_id)->attributes['lb_customer_name'];
            }
            echo '</td>';
            echo '<td>$' . $invoice_information->lb_invoice_total_after_discounts . '</td>';
            echo '<td>';
            $totalTax = 0;
            if ($invoiceTax) {
Esempio n. 4
0
								                border-top: none; border-left: none; border-right: none; box-shadow: none;",
                                                                 "id"=>"payment_{$data->lb_record_primary_key}",
                                                                 "disabled"=>"disabled",
                                            ))', 'htmlOptions' => array('style' => 'width: 130px;text-align: right; '), 'headerHtmlOptions' => array('class' => 'lb-grid-header')), array('header' => Yii::t('lang', 'Notes'), 'type' => 'raw', 'value' => 'CHtml::textArea("payment_note[]","",array(
                                                                 "style"=>"width: 250px; border-top: none; border-left: none; border-right: none; box-shadow: none;",
                                                                 "id"=>"payment_note_{$data->lb_record_primary_key}",
                                        ))', 'htmlOptions' => array('style' => 'width: 100px; '), 'headerHtmlOptions' => array('class' => 'lb-grid-header')))));
?>

<?php 
if (count($invoice->data)) {
    ?>
    <div style="width:100%;overflow:hidden;margin-bottom: 50px;text-align: right;font-weight: bold;">
        <div style="float:left;width:245px;">Total:</div>
        <div style="float:left;width:167px;" id="total_payment_amount"><?php 
    echo LbInvoiceTotal::model()->getTotalInvoiceByCustomer($customer_id);
    ?>
</div>
        <div style="float:left;width:189px;" id="div_total_payment">
            <?php 
    echo CHtml::textField('total_payment', '0.00', array('id' => 'total_payment', "style" => "width: 110px;text-align: right; padding-right: 0px; border-top: none;\n                                                                                 border-left: none; border-right: none; box-shadow: none;font-weight: bold;", "disabled" => "disabled"));
    ?>
        </div>
    </div>
<?php 
}
?>
<script>
    function TotalPaymentAmount(){
        var total_payment = 0;
        //var format_total_payment_amount =0;
Esempio n. 5
0
 /**
  * calculate tax total,
  * return total, but doesn't save to the database
  *
  * @return int invoice tax total
  *
  */
 public function calculateTaxTotal()
 {
     // get invoice total after discount
     $invoiceTotal = LbInvoiceTotal::model()->getInvoiceTotal($this->lb_invoice_id);
     if ($invoiceTotal) {
         $invoice_total_after_discounts = $invoiceTotal->lb_invoice_total_after_discounts;
         // tax is based on this total after discounts;
         $item_total = round(floatval($this->lb_invoice_item_quantity), 2) * round(floatval($this->lb_invoice_item_value) / 100, 2) * $invoice_total_after_discounts;
         $this->lb_invoice_item_total = $item_total;
     }
     return $this->lb_invoice_item_total;
 }
Esempio n. 6
0
<?php

/* @var $this LbInvoiceController */
/* @var $model LbInvoice */
/* @var $ownCompany LbCustomer */
$currency_name = LbGenera::model()->getGeneraSubscription()->lb_genera_currency_symbol;
$thousand = LbGenera::model()->getGeneraSubscription()->lb_thousand_separator;
$decimal = LbGenera::model()->getGeneraSubscription()->lb_decimal_symbol;
$strnum = new LbInvoiceTotal();
// Subtotal Invoice
$invoice_subtotal_arr = LbInvoiceTotal::model()->getInvoiceTotal($model->lb_record_primary_key);
// Discount Invoice
$invoice_discount_arr = LbInvoiceItem::model()->getInvoiceDiscounts($model->lb_record_primary_key, 'ModelArray');
$invoice_discount = "";
foreach ($invoice_discount_arr as $invoice_discount_row) {
    $invoice_discount .= '<tr><td>' . $invoice_discount_row['lb_invoice_item_description'] . ":" . '</td>
                <td>' . $currency_name . $strnum->adddotstring($invoice_discount_row['lb_invoice_item_total'], $thousand, $decimal) . '</td>
            </tr>';
}
//End Discount
// Tax Invoice
$invoice_tax_arr = LbInvoiceItem::model()->getInvoiceTaxes($model->lb_record_primary_key, 'ModelArray');
$invoice_tax = "";
foreach ($invoice_tax_arr as $invoice_tax_row) {
    $tax_arr = LbTax::model()->find('lb_record_primary_key=' . $invoice_tax_row['lb_invoice_item_description']);
    if ($tax_arr['lb_tax_value'] != null && $tax_arr['lb_tax_name'] != null) {
        $tax_name = 'Tax';
        if ($tax_arr['lb_tax_name'] != "") {
            $tax_name = $tax_arr['lb_tax_name'];
        }
        $invoice_tax .= '<tr>
Esempio n. 7
0
         $customer_id = false;
         $invoice_information = LbInvoiceTotal::model()->getInvoiceById($data->lb_record_primary_key);
         $invoiceTax = LbInvoiceItem::model()->getInvoiceTaxById($data->lb_record_primary_key, "TAX");
         $PDFGst .= '<tr>';
         $PDFGst .= '<td>' . $data->lb_invoice_date . '</td>';
         $PDFGst .= '<td>' . $data->lb_invoice_no . '</td>';
         $PDFGst .= '<td>';
         if ($data->lb_invoice_customer_id) {
             $customer_id = $data->lb_invoice_customer_id;
             $PDFGst .= LbCustomer::model()->customerInformation($customer_id)->attributes['lb_customer_name'];
         }
         $PDFGst .= '</td>';
         $invoiceValue = $invoiceValue + $invoice_information->lb_invoice_total_after_taxes;
         $PDFGst .= '<td>$' . $invoice_information->lb_invoice_total_after_taxes . '</td>';
         $PDFGst .= '<td>';
         $totalPaid = LbInvoiceTotal::model()->find('lb_invoice_id=' . intval($data->lb_record_primary_key));
         $AllPaid = $AllPaid + $totalPaid->lb_invoice_total_paid;
         $PDFGst .= $totalPaid->lb_invoice_total_paid;
         $PDFGst .= '</td>';
         $PDFGst .= '<td>';
         $PDFGst .= $totalPaid->lb_invoice_total_paid;
         $PDFGst .= '</td>';
         $invoiceDue = $invoiceDue + $totalPaid->lb_invoice_total_outstanding;
         $PDFGst .= '<td>$' . $totalPaid->lb_invoice_total_outstanding . '</td>';
         $PDFGst .= '</tr>';
     }
 }
 $PDFGst .= '</tbody>';
 $PDFGst .= '<tfoot><tr>
                             <td colspan="3"><b>Sub Total</b></td>
                     <td align="right" style="border-top:1px solid #000">
Esempio n. 8
0
 public function totalInvoiceOutstanding($status, $year = false)
 {
     $data = $this->getInvoiceByStatusAndYear($status, $year);
     $totalAmount = 0;
     foreach ($data as $value) {
         $totalModel = LbInvoiceTotal::model()->find('lb_invoice_id=' . intval($value['lb_record_primary_key']));
         if (count($totalModel) > 0) {
             $totalAmount += $totalModel->lb_invoice_total_outstanding;
         }
     }
     return $totalAmount;
 }
Esempio n. 9
0
 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)));
 }
Esempio n. 10
0
 $invoice_arr = LbInvoice::model()->getInvoiceByCustomerDate($data->lb_record_primary_key, $date_from);
 //$payment = $invoice_arr->customerAddress;
 $customer_name = $data->lb_customer_name;
 //                            echo $customer_name.'<br>';
 $total = 0;
 $i = count($invoice_arr);
 $j = 0;
 $total1 = 0;
 $total2 = 0;
 $total3 = 0;
 $total4 = 0;
 foreach ($invoice_arr as $data_invocie) {
     $j++;
     ?>
  <?php 
     $invoice_total = LbInvoiceTotal::model()->find('lb_invoice_id=' . intval($data_invocie->lb_record_primary_key));
     $lb_invoice = LbInvoice::model()->find('lb_record_primary_key=' . intval($data_invocie->lb_record_primary_key));
     $total = $invoice_total->getTotalInvoiceByCustomer($data->lb_record_primary_key);
     if ($total > 0) {
         if ($Time_Range_search == 0) {
             $PDFAging .= '<tbody>
                     <tr>';
             $PDFAging .= '<td >' . $data_invocie->lb_invoice_no . '</td>
                 <td style="text-align: left;">' . $lb_invoice->lb_invoice_date . '</td>
                 <td style="text-align: left;">';
             $dateNumber = dateNumber($currentDate, $lb_invoice->lb_invoice_date);
             if ($dateNumber >= 0 && $dateNumber <= 30) {
                 $PDFAging .= '$' . $invoice_total->lb_invoice_total_outstanding;
                 $total1 = $total1 + $invoice_total->lb_invoice_total_outstanding;
                 //                                echo $lb_invoice->lb_invoice_date;
             } else {
Esempio n. 11
0
 public function getTotalInvoiceByMonth($year = false, $month = false)
 {
     $status = '("' . LbInvoice::LB_INVOICE_STATUS_CODE_OPEN . '","' . LbInvoice::LB_INVOICE_STATUS_CODE_OVERDUE . '")';
     $model = LbInvoice::model()->findAll('YEAR(lb_invoice_date) = ' . $year . ' AND MONTH(lb_invoice_date) =' . $month . ' AND lb_invoice_status_code IN ' . $status . '');
     $total = 0;
     foreach ($model as $value) {
         $totalArr = LbInvoiceTotal::model()->find('lb_invoice_id = ' . $value->lb_record_primary_key);
         $total += $totalArr->lb_invoice_total_outstanding;
     }
     return $total;
 }
Esempio n. 12
0
 public function getContractIdArrayOutstanding()
 {
     $criteria = new CDbCriteria();
     $dataProvider = LbContracts::model()->getFullRecordsDataProvider();
     $contract_id_arr = array();
     foreach ($dataProvider->data as $data) {
         $TotalAmountInvoice = LbInvoiceTotal::model()->getTotalAmountInvoiceByContract($data->lb_record_primary_key);
         if ($data->lb_contract_amount > $TotalAmountInvoice) {
             $contract_id_arr[] = $data->lb_record_primary_key;
         }
     }
     return $contract_id_arr;
 }
function tableSearch($customer_id_statements = false, $attention_statement = false, $address_option = false, $status = false, $date_from = false, $date_to = false)
{
    $outstanding = 0;
    $paid = 0;
    $tax = 0;
    global $valuePaid;
    global $valueAmount;
    global $valueDue;
    $StatementSearch = LbInvoice::model()->getInvoiceStatement($customer_id_statements, $_POST['attention_statement'], $address_option, $status, $date_from, $date_to);
    //    $addName = LbCustomerAddress::model()->find('lb_record_primary_key='.$address_option);
    //    echo '<span style="font-size: 16px;"><b>Address: </b>'.$addName->lb_customer_address_line_1.'</span><br />';
    if (count($StatementSearch) > 0) {
        if (isset($address_option)) {
            $addName = LbCustomerAddress::model()->find('lb_record_primary_key=' . $address_option);
        }
        echo '<span style="font-size: 16px;"><b>Address: </b>' . $addName->lb_customer_address_line_1 . '</span><br />';
        echo '
                                    <table border="0" width="100%" class="items table table-bordered">
                                    <thead>
                                    <tr>
                                        <th width="250" class="lb-grid-header">' . Yii::t('lang', 'Date') . '</th>
                                        <th width="150" class="lb-grid-header">' . Yii::t('lang', 'Invoice Number') . '</th>
                                        <th width="150" class="lb-grid-header">' . Yii::t('lang', 'Amount') . '</th>
                                        <th width="150" class="lb-grid-header">' . Yii::t('lang', 'Payments') . '</th>
                                        <th width="150" class="lb-grid-header">' . Yii::t('lang', 'Due') . '</th>


                                    </tr>
                                </thead>
                                 <tbody>';
        foreach ($StatementSearch as $data) {
            $getInvoiceById = LbInvoiceTotal::model()->getInvoiceById($data['lb_record_primary_key']);
            $addArr = LbInvoice::model()->findAll('lb_invoice_customer_address_id=' . $data['lb_invoice_customer_address_id']);
            $outstanding = $outstanding + $getInvoiceById['lb_invoice_total_outstanding'];
            $paid = $paid + $getInvoiceById['lb_invoice_total_paid'];
            $tax = $tax + $getInvoiceById['lb_invoice_total_after_taxes'];
            echo '<tr>';
            echo '<td>' . $data['lb_invoice_date'] . '</td>';
            echo '<td>' . $data['lb_invoice_no'] . '</td>';
            echo '<td>' . $getInvoiceById['lb_invoice_total_after_taxes'] . '</td>';
            echo '<td>' . $getInvoiceById['lb_invoice_total_paid'] . '</td>';
            echo '<td>' . $getInvoiceById['lb_invoice_total_outstanding'] . '</td>';
            echo '</tr>';
            $valuePaid = $valuePaid + $getInvoiceById['lb_invoice_total_paid'];
            $valueAmount = $valueAmount + $getInvoiceById['lb_invoice_total_after_taxes'];
            $valueDue = $valueDue + $getInvoiceById['lb_invoice_total_outstanding'];
        }
        echo '</tbody>' . '<tfoot>';
        echo '<tr>';
        echo '<td></td>';
        echo '<td></td>';
        echo '<td style="border-top:1px solid #000" ><b>$' . number_format($tax, 2) . '</b></td>';
        echo '<td style="border-top:1px solid #000"><b>$' . number_format($paid, 2) . '<b></td>';
        echo '<td style="border-top:1px solid #000"><b>$' . number_format($outstanding, 2) . '</b></td>';
        echo '</tr>' . '</tfoot>' . '</table>';
    }
}
Esempio n. 14
0
 public function actionRenew($id)
 {
     $contractModel = LbContracts::model()->findByPk($id);
     $documentModel = new LbContractDocument();
     $paymentModel = new LbPayment();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['LbContracts'])) {
         $LbContracts = $_POST['LbContracts'];
         $model = new LbContracts();
         $model->attributes = $_POST['LbContracts'];
         $model->lb_customer_id = $contractModel->lb_customer_id;
         $model->lb_address_id = $contractModel->lb_address_id;
         $model->lb_contact_id = $contractModel->lb_contact_id;
         $model->lb_contract_type = $contractModel->lb_contract_type;
         $model->lb_contract_status = LbContracts::LB_CONTRACT_STATUS_ACTIVE;
         $model->lb_contract_parent = $contractModel->lb_record_primary_key;
         if ($model->save()) {
             //********* Upload document *****************//
             $document = LbContractDocument::model()->getContractDocument($id);
             foreach ($document->data as $dataDocument) {
                 $documentModel = new LbContractDocument();
                 $documentModel->lb_contract_id = $model->lb_record_primary_key;
                 $documentModel->lb_document_url = $dataDocument->lb_document_url;
                 $documentModel->lb_document_name = $dataDocument->lb_document_name;
                 $documentModel->lb_document_url_icon = $dataDocument->lb_document_url_icon;
                 $documentModel->save();
                 // DONE
             }
             //**** End upload doxument ****//
             ///////////////////////////////////////////////////////////////////////////////
             //********* add new invoice *************/
             if (isset($LbContracts['check_invoice'])) {
                 $invoiceModel = new LbInvoice();
                 // get basic info to assign to this record
                 $ownCompany = LbCustomer::model()->getOwnCompany();
                 $ownCompanyAddress = null;
                 $customerCompany = new LbCustomer();
                 $customerCompany->lb_customer_name = 'Click to choose customer';
                 // get own company address
                 if ($ownCompany->lb_record_primary_key) {
                     // auto assign owner company
                     $invoiceModel->lb_invoice_company_id = $ownCompany->lb_record_primary_key;
                     $own_company_addresses = LbCustomerAddress::model()->getActiveAddresses($ownCompany->lb_record_primary_key, $ownCompany::LB_QUERY_RETURN_TYPE_MODELS_ARRAY);
                     if (count($own_company_addresses)) {
                         $ownCompanyAddress = $own_company_addresses[0];
                         // auto assign owner company's address
                         $invoiceModel->lb_invoice_company_address_id = $ownCompanyAddress->lb_record_primary_key;
                     }
                 }
                 // add infor customer in invoice
                 $invoiceModel->lb_invoice_customer_id = $contractModel->lb_customer_id;
                 $invoiceModel->lb_invoice_customer_address_id = $contractModel->lb_address_id;
                 $invoiceModel->lb_invoice_attention_contact_id = $contractModel->lb_contact_id;
                 if ($invoiceModel->save()) {
                     // Save Lien ket contract va invoice
                     $contrctInvoiceModel = new LbContractInvoice();
                     $contrctInvoiceModel->lb_contract_id = $model->lb_record_primary_key;
                     $contrctInvoiceModel->lb_invoice_id = $invoiceModel->lb_record_primary_key;
                     $contrctInvoiceModel->save();
                     //Update invoice no vaf status I-OPEN
                     $invoiceModel->confirm();
                     // add invoice to database right away.
                     // other fields will be updated on the invoice page later on
                     $invoiceModel->saveUnconfirmed();
                     //
                     // == Prepare line items grid
                     // add 1 line-item by default
                     //
                     $blankItem = new LbInvoiceItem();
                     $blankItem->lb_invoice_id = $invoiceModel->lb_record_primary_key;
                     $blankItem->lb_invoice_item_description = "Contract payment for contract " . $model->lb_contract_no . ", " . $model->lb_contract_type . ", for period " . $model->lb_contract_date_start . " to " . $model->lb_contract_date_end;
                     $blankItem->lb_invoice_item_quantity = 1;
                     $blankItem->lb_invoice_item_value = $model->lb_contract_amount;
                     $blankItem->lb_invoice_item_total = $model->lb_contract_amount;
                     $blankItem->lb_invoice_item_type = LbInvoiceItem::LB_INVOICE_ITEM_TYPE_LINE;
                     $blankItem->save();
                     // add tax
                     $blankTax = new LbInvoiceItem();
                     $default_tax = LbTax::model()->getDefaultTax();
                     //$value_tax = ($default_tax->lb_tax_value/100) * $model->lb_contract_amount;
                     $blankTax->lb_invoice_id = $invoiceModel->lb_record_primary_key;
                     $blankTax->lb_invoice_item_description = $default_tax !== null ? $default_tax->lb_record_primary_key : 'Tax';
                     $blankTax->lb_invoice_item_quantity = 1;
                     $blankTax->lb_invoice_item_value = $default_tax !== null ? $default_tax->lb_tax_value : '0';
                     $blankTax->lb_invoice_item_total = 0;
                     $blankTax->lb_invoice_item_type = LbInvoiceItem::LB_INVOICE_ITEM_TYPE_TAX;
                     $blankTax->save();
                     $invoiceItemModel = new LbInvoiceItem('search');
                     $invoiceItemModel->unsetAttributes();
                     // clear any default values
                     $invoiceItemModel->lb_invoice_id = $invoiceModel->lb_record_primary_key;
                     // totals - create a blank total record, set everything to zero: subtotal, after disc, after tax, paid, outstanding....
                     $invoiceTotal = new LbInvoiceTotal();
                     $invoiceTotal->lb_invoice_id = $invoiceModel->lb_record_primary_key;
                     $invoiceTotal->lb_invoice_revision_id = 0;
                     // latest version
                     $invoiceTotal->lb_invoice_subtotal = $model->lb_contract_amount;
                     $invoiceTotal->lb_invoice_total_after_discounts = $model->lb_contract_amount;
                     $invoiceTotal->lb_invoice_total_after_taxes = $model->lb_contract_amount;
                     $invoiceTotal->lb_invoice_total_outstanding = $model->lb_contract_amount;
                     $invoiceTotal->lb_invoice_total_paid = 0;
                     $invoiceTotal->save();
                     // == end items grid data prep
                     // Uncomment the following line if AJAX validation is needed
                     // $this->performAjaxValidation($model);
                     $invoiceDiscountModel = new LbInvoiceItem();
                     $invoiceDiscountModel->lb_invoice_item_type = LbInvoiceItem::LB_INVOICE_ITEM_TYPE_DISCOUNT;
                     $invoiceTaxModel = new LbInvoiceItem();
                     $invoiceTaxModel->lb_invoice_item_type = LbInvoiceItem::LB_INVOICE_ITEM_TYPE_TAX;
                     //*** End add invoice **/
                     ///////////////////////////////////////////////////////////////////////////////////////////////
                     //************** Add payment *************//
                     if (isset($LbContracts['payment_amount']) && $LbContracts['payment_amount'] != 0) {
                         $paymentModel = new LbPayment();
                         $paymentModel->attributes = $_POST['LbPayment'];
                         $paymentModel->lb_payment_customer_id = $contractModel->lb_customer_id;
                         $paymentModel->lb_payment_no = LbPayment::model()->FormatPaymentNo();
                         $paymentModel->lb_payment_total = $LbContracts['payment_amount'];
                         if ($paymentModel->save()) {
                             LbPayment::model()->setPaymentNextNum(LbPayment::model()->getPaymentNextNum());
                             $paymentItemModel = new LbPaymentItem();
                             $paymentItemModel->lb_payment_id = $paymentModel->lb_record_primary_key;
                             $paymentItemModel->lb_invoice_id = $invoiceModel->lb_record_primary_key;
                             $paymentItemModel->lb_payment_item_note = "";
                             $paymentItemModel->lb_payment_item_amount = $LbContracts['payment_amount'];
                             if ($paymentItemModel->save()) {
                                 $invoice_total = LbInvoiceTotal::model()->getInvoiceTotal($paymentItemModel->lb_invoice_id);
                                 if ($invoice_total) {
                                     $invoice_total->calculateInvoicetotalPaid($paymentItemModel->lb_invoice_id);
                                     $total_outstanding = $invoice_total->calculateInvoiceTotalOutstanding();
                                     if ($total_outstanding) {
                                         //Update Status
                                         LbInvoice::model()->InvoiceUpdateStatus($invoiceModel->lb_record_primary_key);
                                     }
                                 }
                                 echo "{succes}";
                             }
                         }
                     }
                 }
             }
             $contractModel->lb_contract_status = LbContracts::LB_CONTRACT_STATUS_HAS_RENEWED;
             $contractModel->save();
             $this->redirect(array('view', 'id' => $model->lb_record_primary_key));
         }
     }
     $customer_id = "";
     if (isset($_POST['customer_id'])) {
         $customer_id = $_POST['customer_id'];
     }
     $this->render('_form_renew', array('model' => $contractModel, 'paymentModel' => $paymentModel));
 }