/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { // are we creating invoice or quotation? if (isset($_GET['group']) && $_GET['group'] == strtolower(LbInvoiceGeneric::LB_INVOICE_GROUP_INVOICE)) { $model = new LbInvoice(); } else { $model = new LbQuotation(); } // 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 $model->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 $model->lb_invoice_company_address_id = $ownCompanyAddress->lb_record_primary_key; } } // add invoice to database right away. // other fields will be updated on the invoice page later on $model->saveUnconfirmed(); // // == Prepare line items grid // add 1 line-item by default // $blankItem = new LbInvoiceItem(); $blankItem->addBlankItem($model->lb_record_primary_key); $blankTax = new LbInvoiceItem(); $blankTax->addBlankTax($model->lb_record_primary_key); $invoiceItemModel = new LbInvoiceItem('search'); $invoiceItemModel->unsetAttributes(); // clear any default values $invoiceItemModel->lb_invoice_id = $model->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->createBlankTotal($model->lb_record_primary_key); // == 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; if (isset($_POST['LbInvoice'])) { $model->attributes = $_POST['LbInvoice']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->lb_record_primary_key)); } } $this->redirect(array('view', 'id' => $model->lb_record_primary_key)); /** LBApplication::render($this,'create',array( //'save_unconfirmed'=>$save_unconfirmed, 'model'=>$model, 'invoiceItemModel'=>$invoiceItemModel, 'invoiceDiscountModel'=>$invoiceDiscountModel, 'invoiceTaxModel'=>$invoiceTaxModel, 'invoiceTotal'=>$invoiceTotal, ));**/ /** LBApplication::render($this,'view',array( 'model'=>$model, 'invoiceItemModel'=>$invoiceItemModel, 'invoiceDiscountModel'=>$invoiceDiscountModel, 'invoiceTaxModel'=>$invoiceTaxModel, 'invoiceTotal'=>$invoiceTotal, ));**/ }