/**
  * Tinh total amount invoice cua contract
  * @param int $contract_id
  * @return float totalAmountInvoiceContract
  */
 public function getTotalAmountInvoiceByContract($contract_id)
 {
     $contractInvoice_arr = LbContractInvoice::model()->getContractInvoice($contract_id);
     $totalAmountInvoice = 0;
     foreach ($contractInvoice_arr->data as $dataContractInvoice) {
         $totalModel = LbInvoiceTotal::model()->find('lb_invoice_id=' . intval($dataContractInvoice['lb_invoice_id']));
         if (count($totalModel) > 0) {
             $totalAmountInvoice += $totalModel->lb_invoice_total_after_taxes;
         }
     }
     return $totalAmountInvoice;
 }
Beispiel #2
0
<div style="margin-top: 30px;">
    <div style="margin-top: 40px;" class="panel-header-title">
        <div class="panel-header-title-left" style="width: 20%">
            <h4><?php 
echo Yii::t('lang', 'Related Invoice');
?>
</h4>
        </div>
        <div class="panel-header-title-right">
            <?php 
if ($canAddInvoice && $canEdit) {
    ?>
                <a href="<?php 
    echo $this->createUrl('createInvoice', array('id' => $model->lb_record_primary_key));
    ?>
"><i class="icon-plus"></i> <?php 
    echo Yii::t('lang', 'New Invoice');
    ?>
</a>
            <?php 
}
?>
        </div>
    </div>
    <?php 
$this->widget('bootstrap.widgets.TbGridView', array('id' => 'lb-contracts-invoice_grid', 'type' => 'striped bordered condensed', 'dataProvider' => LbContractInvoice::model()->getContractInvoice($model->lb_record_primary_key), 'template' => '{items}', 'htmlOptions' => array('width' => '500'), 'columns' => array(array('header' => Yii::t('lang', 'Invoice No'), 'type' => 'raw', 'value' => '
                            LBApplication::workspaceLink($data->invoice->lb_invoice_no,  LbInvoice::model()->getViewInvoiceURL($data->invoice->lb_record_primary_key,$data->invoice->customer->lb_customer_name));
                        '), array('header' => Yii::t('lang', 'Date'), 'type' => 'raw', 'value' => '$data->invoice->lb_invoice_date'), array('header' => Yii::t('lang', 'Due Date'), 'type' => 'raw', 'value' => '$data->invoice->lb_invoice_due_date'), array('header' => Yii::t('lang', 'Amount'), 'type' => 'raw', 'value' => '$data->invoice->total_invoice->lb_invoice_total_after_taxes'), array('header' => Yii::t('lang', 'Paid'), 'type' => 'raw', 'value' => '$data->invoice->total_invoice->lb_invoice_total_paid'), array('header' => Yii::t('lang', 'Outstanding'), 'type' => 'raw', 'value' => '$data->invoice->total_invoice->lb_invoice_total_outstanding'))));
?>
</div>
Beispiel #3
0
 /**
  * delete invoice
  * line items, discounts, taxes, totals, trails, ...
  * @return bool|void
  */
 public function delete()
 {
     // delete invoice
     $id = $this->lb_record_primary_key;
     $result = parent::delete();
     if ($result) {
         // delete line items
         $line_items = LbInvoiceItem::model()->getInvoiceItems($id, self::LB_QUERY_RETURN_TYPE_MODELS_ARRAY);
         foreach ($line_items as $l_item) {
             $l_item->delete();
         }
         // delete discounts
         $discounts = LbInvoiceItem::model()->getInvoiceDiscounts($id, self::LB_QUERY_RETURN_TYPE_MODELS_ARRAY);
         foreach ($discounts as $disc) {
             $disc->delete();
         }
         // delete taxes
         $taxes = LbInvoiceItem::model()->getInvoiceTaxes($id, self::LB_QUERY_RETURN_TYPE_MODELS_ARRAY);
         foreach ($taxes as $tx) {
             $tx->delete();
         }
         // delete totals
         $total = LbInvoiceTotal::model()->getInvoiceTotal($id);
         if ($total) {
             $total->delete();
         }
         // delete invoice in contract
         $invoiceByContract = LbContractInvoice::model()->find('lb_invoice_id=' . intval($id));
         if (count($invoiceByContract) > 0) {
             $invoiceByContract->delete();
         }
     }
 }
 public function actionCreateInvoice($id)
 {
     $model = LbContracts::model()->findByPk($id);
     //********* add new 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 = $model->lb_customer_id;
     $invoiceModel->lb_invoice_customer_address_id = $model->lb_address_id;
     $invoiceModel->lb_invoice_attention_contact_id = $model->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 = 0;
         $blankItem->lb_invoice_item_total = 0;
         $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 = 0;
         $invoiceTotal->lb_invoice_total_after_discounts = 0;
         $invoiceTotal->lb_invoice_total_after_taxes = 0;
         $invoiceTotal->lb_invoice_total_outstanding = 0;
         $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 **/
         //LBApplication::redire(array('lbInvoice/default/view','id'=>$invoiceModel->lb_record_primary_key));
         $this->redirect(array('view', 'id' => $model->lb_record_primary_key));
     }
 }