Ejemplo n.º 1
0
 public function actionajaxDeleteItemDiscount($id)
 {
     $vendorDiscount = LbVendorDiscount::model()->findByPk($id);
     $type = $vendorDiscount['lb_vendor_type'];
     if ($type == LbVendorDiscount::LB_VENDOR_ITEM_TYPE_DISCOUNT) {
         $return_type = LbVendorTotal::LB_VENDOR_ITEM_TYPE_TOTAL;
         $record_id = $vendorDiscount['lb_vendor_id'];
     } else {
         $return_type = LbVendorTotal::LB_VENDOR_INVOICE_TOTAL;
         $record_id = $vendorDiscount['lb_vendor_invoice_id'];
     }
     $vendorDiscount->deleteByPk($id);
     LbVendorTotal::model()->totalAfterDiscount($record_id, $type, $return_type);
 }
Ejemplo n.º 2
0
$modelItem = LbVendorItem::model()->findAll('lb_vendor_id=55');
if (count($modelItem) > 0) {
    $tItem = '<table border="1" style="width:100%;" cellpadding="0" cellspacing="0">';
    $tItem .= '<tr>' . '<td style="width:200px;height:30px">Item</td>' . '<td style="width:100px;">Quantity</td>' . '<td style="width:200px;">Price</td>' . '<td style="width:200px;">Total</td>' . '</tr>';
    foreach ($modelItem as $dataItem) {
        $tItem .= '<tr>' . '<td style="height:15px">' . $dataItem['lb_vendor_item_description'] . '</td>' . '<td>' . $dataItem['lb_vendor_item_quantity'] . '</td>' . '<td>' . $dataItem['lb_vendor_item_price'] . '</td>' . '<td>' . $dataItem['lb_vendor_item_amount'] . '</td>' . '</tr>';
    }
    $tItem .= '</table>';
    echo $tItem . '<br />';
}
//Total
$modelTotal = LbVendorTotal::model()->getVendorTotal($model->lb_record_primary_key, LbVendorTotal::LB_VENDOR_ITEM_TYPE_TOTAL);
//Discount
$discountItem = '<table border="0" style="width:100%;" cellpadding="0" cellspacing="0">';
$discountItem .= '<tr>' . '<td style="width:100px;"><b>Sub Total : </b></td>' . '<td style="border-bottom:1px solid black">$' . $modelTotal->lb_vendor_subtotal . '</td>' . '</tr>';
$discountAll = LbVendorDiscount::model()->findAll('lb_vendor_id = ' . $model->lb_record_primary_key);
if (count($discountAll) > 0) {
    $discountItem .= '<tr>' . '<td><b>Discount  </b></td>' . '</tr>';
    foreach ($discountAll as $valueDiscount) {
        $discountItem .= '<tr>' . '<td>' . $valueDiscount['lb_vendor_description'] . '</td>' . '<td>$' . $valueDiscount['lb_vendor_value'] . '</td>' . '</tr>';
    }
}
//tax
$TaxAll = LbVendorTax::model()->findAll('lb_vendor_id = ' . $model->lb_record_primary_key);
if (count($TaxAll) > 0) {
    $discountItem .= '<tr>' . '<td  ><b>Tax  </b></td>' . '<td style="border-top:1px solid black" ></td>' . '</tr>';
    foreach ($TaxAll as $valueTax) {
        $discountItem .= '<tr>' . '<td>' . $valueTax['lb_tax_name'] . '</td>' . '<td>$' . $valueTax['lb_vendor_tax_total'] . '</td>' . '</tr>';
    }
}
$discountItem .= '<tr>' . '<td style=""><b>Total : </b></td>' . '<td style="border-top:1px solid black">$' . $modelTotal->lb_vendor_last_tax . '</td>' . '</tr>';
Ejemplo n.º 3
0
 function actionAjaxCreateVendorInvoice($id)
 {
     $model = $this->loadModel($id);
     $quotationItem = LbVendorItem::model()->getVendorItems($id, LbVendorItem::LB_VENDOR_ITEM_TYPE_LINE, LbVendorItem::LB_QUERY_RETURN_TYPE_MODELS_ARRAY);
     $quotationDiscount = LbVendorDiscount::model()->getVendorDiscounts($id, LbVendorDiscount::LB_VENDOR_ITEM_TYPE_DISCOUNT, LbVendorDiscount::LB_QUERY_RETURN_TYPE_MODELS_ARRAY);
     $quotationTax = LbVendorTax::model()->getTaxByVendor($id, LbVendorTax::LB_VENDOR_ITEM_TYPE_TAX, LbVendorTax::LB_QUERY_RETURN_TYPE_MODELS_ARRAY);
     $quotationTotal = LbVendorTotal::model()->getVendorTotal($model->lb_record_primary_key, LbVendorTotal::LB_VENDOR_ITEM_TYPE_TOTAL);
     $invoiceModel = new LbVendorInvoice();
     $invoice_number_int = LbVendorInvoice::model()->getVINextNum();
     $invoiceModel->lb_vd_invoice_no = LbVendorInvoice::model()->formatVINextNumFormatted($invoice_number_int);
     $invoiceModel->lb_vd_invoice_status = LbVendorInvoice::LB_VD_CODE_OPEN;
     // invoice date
     $invoiceModel->lb_vd_invoice_date = date('Y-m-d');
     $invoiceModel->lb_vd_invoice_due_date = date('Y-m-d');
     // invoice group
     //        $invoiceModel->lb_invoice_group = LbInvoice::LB_INVOICE_GROUP_INVOICE;
     // invoice base64_decode
     $invoiceModel->lb_vd_invoice_encode = LbVendorInvoice::model()->setBase64_decodePO();
     // invoice note
     $invoiceModel->lb_vd_invoice_notes = $model->lb_vendor_notes;
     $invoiceModel->lb_vd_invoice_company_id = $model->lb_vendor_company_id;
     $invoiceModel->lb_vd_invoice_company_address_id = $model->lb_vendor_company_address_id;
     $invoiceModel->lb_vd_invoice_supplier_id = $model->lb_vendor_supplier_id;
     $invoiceModel->lb_vd_invoice_supplier_address_id = $model->lb_vendor_supplier_address;
     $invoiceModel->lb_vd_invoice_supplier_attention_id = $model->lb_vendor_supplier_attention_id;
     $invoiceModel->lb_vendor_id = $model->lb_record_primary_key;
     $invoiceModel->lb_vd_invoice_subject = $model->lb_vendor_subject;
     $invoiceModel->lb_vd_invoice_category = $model->lb_vendor_category;
     // invoice internal note
     //        $invoiceModel->lb_invoice_internal_note = $model->lb_quotation_internal_note;
     if ($invoiceModel->insert()) {
         // copy line item
         foreach ($quotationItem as $q_item) {
             $vendorItem = new LbVendorItem();
             $vendorItem->lb_vendor_id = $id;
             $vendorItem->lb_vendor_invoice_id = $invoiceModel->lb_record_primary_key;
             $vendorItem->lb_vendor_type = LbVendorItem::LB_VENDOR_INVOICE_ITEM_TYPE_LINE;
             $vendorItem->lb_vendor_item_quantity = $q_item->lb_vendor_item_quantity;
             $vendorItem->lb_vendor_item_price = $q_item->lb_vendor_item_price;
             $vendorItem->lb_vendor_item_amount = $q_item->lb_vendor_item_amount;
             $vendorItem->lb_vendor_item_description = $q_item->lb_vendor_item_description;
             $vendorItem->insert();
         }
         // copy tax item
         foreach ($quotationTax as $q_tax) {
             $taxInvoiceVendor = new LbVendorTax();
             $taxInvoiceVendor->lb_vendor_invoice_id = $invoiceModel->lb_record_primary_key;
             $taxInvoiceVendor->lb_vendor_id = $id;
             $taxInvoiceVendor->lb_vendor_type = LbVendorTax::LB_VENDOR_INVOICE_ITEM_TYPE_TAX;
             $taxInvoiceVendor->lb_vendor_tax_id = $q_tax->lb_vendor_tax_id;
             $taxInvoiceVendor->lb_tax_name = $q_tax->lb_tax_name;
             $taxInvoiceVendor->lb_vendor_tax_value = $q_tax->lb_vendor_tax_value;
             $taxInvoiceVendor->lb_vendor_tax_total = $q_tax->lb_vendor_tax_total;
             $taxInvoiceVendor->insert();
         }
         //
         //            // copy discount item
         foreach ($quotationDiscount as $q_discount) {
             $discountVendorInvoice = new LbVendorDiscount();
             $discountVendorInvoice->lb_vendor_id = $id;
             $discountVendorInvoice->lb_vendor_invoice_id = $invoiceModel->lb_record_primary_key;
             $discountVendorInvoice->lb_vendor_description = $q_discount->lb_vendor_description;
             $discountVendorInvoice->lb_vendor_value = $q_discount->lb_vendor_value;
             $discountVendorInvoice->lb_vendor_type = LbVendorDiscount::LB_VENDOR_INVOICE_ITEM_TYPE_DISCOUNT;
             $discountVendorInvoice->insert();
         }
         //
         //            // Copy Total
         $vendorItem = new LbVendorTotal();
         $vendorItem->lb_vendor_invoice_id = $invoiceModel->lb_record_primary_key;
         $vendorItem->lb_vendor_id = $id;
         $vendorItem->lb_vendor_type = LbVendorTotal::LB_VENDOR_INVOICE_TOTAL;
         $vendorItem->lb_vendor_subtotal = $quotationTotal->lb_vendor_subtotal;
         $vendorItem->lb_vendor_total_last_discount = $quotationTotal->lb_vendor_total_last_discount;
         $vendorItem->lb_vendor_last_tax = $quotationTotal->lb_vendor_last_tax;
         $vendorItem->lb_vendor_last_paid = $quotationTotal->lb_vendor_last_paid;
         $vendorItem->lb_vendor_last_outstanding = $quotationTotal->lb_vendor_last_outstanding;
         $vendorItem->insert();
         // redirect Invoice
         //            $url_invoice = $model->customer ? LbInvoice::model()->getViewURL($model->customer->lb_customer_name,null,$invoiceModel->lb_record_primary_key) : LbInvoice::model()->getViewURL("No customer",null,$invoiceModel->lb_record_primary_key);
         //            $this->redirect($url_invoice);
     }
 }
Ejemplo n.º 4
0
 public function totalAfterDiscount($id, $type, $return_type)
 {
     $discount = LbVendorDiscount::model()->calculateDiscount($id, $type);
     $pk = $this->getIdVendorTotalByItem($id, $return_type);
     $total = LbVendorTotal::model()->findByPk($pk);
     $subtotal = $total->lb_vendor_subtotal;
     //discount
     $discount_end = $subtotal - $discount;
     //update last discount
     $total->lb_vendor_total_last_discount = $discount_end;
     //total tax
     $total_tax = $discount_end;
     //update tax
     if ($type == LbVendorDiscount::LB_VENDOR_INVOICE_ITEM_TYPE_DISCOUNT) {
         $taxAll = LbVendorTax::model()->findAll("lb_vendor_invoice_id =  " . $id);
     } else {
         $taxAll = LbVendorTax::model()->findAll("lb_vendor_id =  " . $id);
     }
     foreach ($taxAll as $data) {
         $tax = new LbVendorTax();
         $tax_value = $total_tax * $data['lb_vendor_tax_value'] / 100;
         $tax->updateTax($data['lb_record_primary_key'], $tax_value);
     }
     //update last tax
     if ($type == LbVendorDiscount::LB_VENDOR_INVOICE_ITEM_TYPE_DISCOUNT) {
         $last_tax = $discount_end + LbVendorTax::model()->calculateTax($id, LbVendorTax::LB_VENDOR_INVOICE_ITEM_TYPE_TAX);
     } else {
         $last_tax = $discount_end + LbVendorTax::model()->calculateTax($id, LbVendorTax::LB_VENDOR_ITEM_TYPE_TAX);
     }
     $total->lb_vendor_last_tax = $last_tax;
     $total->lb_vendor_last_outstanding = $last_tax - $total->lb_vendor_last_paid;
     $total->update();
 }