Ejemplo n.º 1
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.º 2
0
 public function addTotalVendor($record_id, $type)
 {
     $vendorItem = new LbVendorTotal();
     if ($type == self::LB_VENDOR_ITEM_TYPE_TOTAL) {
         $vendorItem->lb_vendor_id = $record_id;
         $vendorItem->lb_vendor_invoice_id = 0;
     }
     if ($type == self::LB_VENDOR_INVOICE_TOTAL) {
         $vendorItem->lb_vendor_invoice_id = $record_id;
         $vendorItem->lb_vendor_id = 0;
     }
     $vendorItem->lb_vendor_type = $type;
     $vendorItem->lb_vendor_subtotal = 0;
     $vendorItem->lb_vendor_total_last_discount = 0;
     $vendorItem->lb_vendor_last_tax = 0;
     $vendorItem->lb_vendor_last_paid = 0;
     $vendorItem->lb_vendor_last_outstanding = 0;
     if ($vendorItem->insert()) {
         return $vendorItem->lb_record_primary_key;
     } else {
         return false;
     }
 }