Changeset 2096132
- Timestamp:
- 05/28/2019 12:40:46 AM (7 years ago)
- Location:
- expert-invoice
- Files:
-
- 1 deleted
- 4 edited
-
tags/1.0.1 (deleted)
-
trunk/application/controllers/InvoiceController.php (modified) (8 diffs)
-
trunk/application/models/Invoice.php (modified) (14 diffs)
-
trunk/expert-invoice.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
expert-invoice/trunk/application/controllers/InvoiceController.php
r2080123 r2096132 20 20 } 21 21 22 22 /** 23 * Specifies the access control rules. 24 * This method is used by the 'accessControl' filter. 25 * @return array access control rules 26 */ 23 27 public function accessRules() { 24 28 return array( … … 41 45 } 42 46 43 47 /** 48 * Displays a particular model. 49 * @param integer $id the ID of the model to be displayed 50 */ 44 51 public function actionView($id) { 45 52 $model = $this->loadModel($id); … … 59 66 } 60 67 61 68 /** 69 * Creates a new model. 70 * If creation is successful, the browser will be redirected to the 'view' page. 71 */ 62 72 public function actionSave() { 63 73 $model = new Invoice(); … … 92 102 93 103 94 104 /** 105 * Updates a particular model. 106 * If update is successful, the browser will be redirected to the 'view' page. 107 * @param integer $id the ID of the model to be updated 108 */ 95 109 public function actionUpdate($id) { 96 110 $model = $this->loadModel($id); 97 111 if (!empty($_POST)) { 98 112 $model->setAttributes($_POST); 99 $model->type = Invoice::TYPE_INVOICE; if ($model->save()) { 113 $model->type = Invoice::TYPE_INVOICE; //FromQuote 114 if ($model->save()) { 100 115 $model->saveItems(isset($_POST['items']) ? $_POST['items'] : []); 101 116 $model->deleteItems(isset($_POST['deletedItems']) ? $_POST['deletedItems'] : []); … … 114 129 } 115 130 116 131 /** 132 * Duplicates a particular model. 133 * If update is successful, the browser will be redirected to the 'view' page. 134 * @param integer $id the ID of the model to be updated 135 */ 117 136 public function actionDuplicate($id) { 118 137 $model = $this->loadModel($id); 119 138 $items = $model->getInvoiceItems(); 139 foreach($items as $item){ 140 $item->id = ''; 141 } 120 142 $model->id = ''; 121 143 $model->receiptNumber = $model->getNewInvoiceNumber(); … … 174 196 175 197 176 198 /** 199 * Deletes a particular model. 200 * If deletion is successful, the browser will be redirected to the 'admin' page. 201 * @param integer $id the ID of the model to be deleted 202 */ 177 203 public function actionDelete($id) { 178 204 $model = $this->loadModel($id); … … 189 215 } 190 216 191 217 /** 218 * Manages all models. 219 */ 192 220 public function actionIndex() { 193 221 $model = new Invoice('search'); 194 $model->unsetAttributes(); if (isset($_GET['Invoice'])) { 222 $model->unsetAttributes(); // clear any default values 223 if (isset($_GET['Invoice'])) { 195 224 $model->attributes = $_GET['Invoice']; 196 225 } … … 201 230 } 202 231 203 232 /** 233 * Returns the data model based on the primary key given in the GET variable. 234 * If the data model is not found, an HTTP exception will be raised. 235 * @param integer $id the ID of the model to be loaded 236 * @return Invoice the loaded model 237 * @throws HttpException 238 */ 204 239 public function loadModel($id) { 205 240 $model = Invoice::model()->findByPk($id); -
expert-invoice/trunk/application/models/Invoice.php
r2080123 r2096132 13 13 use expertinvoice\application\utils\Helper; 14 14 15 15 /** 16 * This is the model class for table "{{invoice}}". 17 * 18 * The followings are the available columns in table '{{invoice}}': 19 * @property integer $id 20 * @property integer $receiptNumber 21 * @property integer $customerId 22 * @property string $createdDate 23 * @property string $updatedDate 24 * @property integer $termsDays 25 * @property integer $salesPerson 26 * @property string $privateComment 27 * @property string $comment 28 * @property integer $termsId 29 * @property integer $type 30 * @property string $amountDue 31 * @property string $totalTax 32 * @property integer $hasRefund 33 * @property float $discount 34 * @property float $totalDiscount 35 * @property string $invoicedDate 36 * @property integer $quoteNumber 37 * @property string $title 38 * @property string $dueDate 39 * @property integer $status 40 * 41 * The followings are the available model relations: 42 * @property Customer $customer 43 * @property InvoiceItem[] $invoiceItems 44 * @property Payment[] $payments 45 */ 16 46 class Invoice extends ActiveRecord { 17 47 … … 25 55 private $_totalPaid; 26 56 27 57 /** 58 * @return string the associated database table name 59 */ 28 60 public function tableName() { 29 61 return '{{expertinvoice_invoice}}'; … … 39 71 } 40 72 41 73 /** 74 * @return array validation rules for model attributes. 75 */ 42 76 public function rules() { 43 return array( 77 // NOTE: you should only define rules for those attributes that 78 // will receive user inputs. 79 return array( 44 80 array('customerId,invoicedDate,title,dueDate', 'required'), 45 81 array('receiptNumber', 'required', 'condition' => function($model) { … … 50 86 array('amountDue, totalTax,discount,totalDiscount', 'length', 'max' => 15), 51 87 array('privateComment, comment', 'safe'), 52 array('id, receiptNumber, customer, customerId, createdDate, termsDays, privateComment, comment, termsId, type, amountDue, totalTax, hasRefund', 'safe', 'on' => 'search'), 88 // The following rule is used by search(). 89 // @todo Please remove those attributes that should not be searched. 90 array('id, receiptNumber, customer, customerId, createdDate, termsDays, privateComment, comment, termsId, type, amountDue, totalTax, hasRefund', 'safe', 'on' => 'search'), 53 91 ); 54 92 } … … 61 99 } 62 100 63 101 /** 102 * @return Customer */ 64 103 public function getCustomer() { 65 104 return Customer::model()->findByPk($this->customerId); 66 105 } 67 106 68 107 /** 108 * @return InvoiceItem[] 109 */ 69 110 public function getInvoiceItems() { 70 111 return InvoiceItem::model()->findAllByAttributes(array('invoiceId' => $this->getPrimaryKey())); 71 112 } 72 113 73 114 /** 115 * @return Payment[] 116 */ 74 117 public function getPayments() { 75 118 return Payment::model()->findAllByAttributes(array('invoiceId' => $this->getPrimaryKey())); … … 80 123 } 81 124 82 125 /** 126 * Retrieves a list of models based on the current search/filter conditions. 127 * 128 * Typical usecase: 129 * - Initialize the model fields with values from filter form. 130 * - Execute this method to get ActiveDataProvider instance which will filter 131 * models according to data in model fields. 132 * 133 * @return ActiveDataProvider the data provider that can return the models 134 * based on the search/filter conditions. 135 */ 83 136 public function invoiceSearch() { 84 137 $q = isset($_GET['q']) ? $_GET['q'] : null; … … 106 159 } 107 160 108 161 /** 162 * Retrieves a list of models based on the current search/filter conditions. 163 * 164 * Typical usecase: 165 * - Initialize the model fields with values from filter form. 166 * - Execute this method to get ActiveDataProvider instance which will filter 167 * models according to data in model fields. 168 * 169 * @return ActiveDataProvider the data provider that can return the models 170 * based on the search/filter conditions. 171 */ 109 172 public function quoteSearch() { 110 173 $q = isset($_GET['q']) ? $_GET['q'] : null; … … 130 193 } 131 194 132 195 /** 196 * Returns the static model of the specified AR class. 197 * Please note that you should have this exact method in all your CActiveRecord descendants! 198 * @param string $className active record class name. 199 * @return Invoice the static model class 200 */ 133 201 public static function model($className = __CLASS__) { 134 202 return parent::model($className); … … 182 250 $stock = null; 183 251 foreach ($stocks as $attrs) { 184 if ( isset($attrs['id'])) {252 if (!empty($attrs['id'])) { 185 253 $stock = InvoiceItem::model()->findByPk($attrs['id']); 186 254 if ($stock == null) { … … 243 311 } 244 312 245 313 /** 314 * 315 * @param float $amount 316 * @param integer $paymentMethod 317 * @param string $transactionCode 318 */ 246 319 public function paymentMade($amount, $paymentMethod, $transactionCode) { 247 320 if (!Payment::model()->exists('transactionCode=:t AND paymentMethod=:p', array(':t' => $transactionCode, ':p' => $paymentMethod))) { … … 268 341 } 269 342 270 343 /** 344 * 345 * @param Customer $customer 346 * @param Template $template 347 */ 271 348 public function sendEmail($customer, $template) { 272 349 $attachment = $this->getInvoicePdf(); … … 277 354 } 278 355 279 356 /** 357 * 358 * @param type $template 359 * @param Customer $customer 360 * @param Invoice $model 361 */ 280 362 private function getEmailContent($template, $customer) { 281 363 $url = $this->getViewUrl(); … … 292 374 private function getInvoicePdf() { 293 375 require_once(FileHelper::getPluginDirPath() . '/expert-invoice/vendor/autoload.php'); 376 // use Dompdf\Dompdf; 294 377 $title = ($this->type == Invoice::TYPE_INVOICE ? 'Invoice' . $this->receiptNumber : 'Quote' . $this->quoteNumber); 295 378 $fileName = FileHelper::getTmpDir() . DIRECTORY_SEPARATOR . $title . '.pdf'; … … 299 382 $options->set('defaultFont', 'Helvetica'); 300 383 $options->set('isRemoteEnabled', true); 301 $dompdf = new \Dompdf\Dompdf($options); 384 // instantiate and use the dompdf class 385 $dompdf = new \Dompdf\Dompdf($options); 302 386 $dompdf->loadHtml($html); 303 $dompdf->setPaper('A4', 'landscape'); 304 $dompdf->render(); 305 $output = $dompdf->output(); 387 // (Optional) Setup the paper size and orientation 388 $dompdf->setPaper('A4', 'landscape'); 389 // Render the HTML as PDF 390 $dompdf->render(); 391 // Output the generated PDF to Browser 392 $output = $dompdf->output(); 306 393 file_put_contents($fileName, $output); 394 // \envoqon\App::log($fileName, envoqon\logging\Logger::LEVEL_ERROR); 307 395 return $fileName; 308 396 } -
expert-invoice/trunk/expert-invoice.php
r2080123 r2096132 6 6 Description: A feature-packed and flexible invoicing system. 7 7 Author: Envoqon 8 Version: 1.0 8 Version: 1.0.1 9 9 Author URI: https://www.envoqon.com/ 10 10 Text Domain: expert-invoice -
expert-invoice/trunk/readme.txt
r2083174 r2096132 89 89 7. Set up your currency, date formats, etc 90 90 8. Invoice listings page 91 92 == Changelog == 93 94 = 1.0.1 = 95 - Fixed issues with duplicate items not saving.
Note: See TracChangeset
for help on using the changeset viewer.