Plugin Directory

Changeset 2096132


Ignore:
Timestamp:
05/28/2019 12:40:46 AM (7 years ago)
Author:
envoqon
Message:

updated to fix duplicate invoice not saving items

Location:
expert-invoice
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • expert-invoice/trunk/application/controllers/InvoiceController.php

    r2080123 r2096132  
    2020    }
    2121
    22    
     22    /**
     23     * Specifies the access control rules.
     24     * This method is used by the 'accessControl' filter.
     25     * @return array access control rules
     26     */
    2327    public function accessRules() {
    2428        return array(
     
    4145    }
    4246
    43    
     47    /**
     48     * Displays a particular model.
     49     * @param integer $id the ID of the model to be displayed
     50     */
    4451    public function actionView($id) {
    4552        $model = $this->loadModel($id);
     
    5966    }
    6067
    61    
     68    /**
     69     * Creates a new model.
     70     * If creation is successful, the browser will be redirected to the 'view' page.
     71     */
    6272    public function actionSave() {
    6373        $model = new Invoice();
     
    92102   
    93103
    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     */
    95109    public function actionUpdate($id) {
    96110        $model = $this->loadModel($id);
    97111        if (!empty($_POST)) {
    98112            $model->setAttributes($_POST);
    99             $model->type = Invoice::TYPE_INVOICE;             if ($model->save()) {
     113            $model->type = Invoice::TYPE_INVOICE; //FromQuote
     114            if ($model->save()) {
    100115                $model->saveItems(isset($_POST['items']) ? $_POST['items'] : []);
    101116                $model->deleteItems(isset($_POST['deletedItems']) ? $_POST['deletedItems'] : []);
     
    114129    }
    115130
    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     */
    117136    public function actionDuplicate($id) {
    118137        $model = $this->loadModel($id);
    119138        $items = $model->getInvoiceItems();
     139        foreach($items as $item){
     140            $item->id = '';
     141        }
    120142        $model->id = '';
    121143        $model->receiptNumber = $model->getNewInvoiceNumber();
     
    174196   
    175197
    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     */
    177203    public function actionDelete($id) {
    178204        $model = $this->loadModel($id);
     
    189215    }
    190216
    191    
     217    /**
     218     * Manages all models.
     219     */
    192220    public function actionIndex() {
    193221        $model = new Invoice('search');
    194         $model->unsetAttributes();          if (isset($_GET['Invoice'])) {
     222        $model->unsetAttributes();  // clear any default values
     223        if (isset($_GET['Invoice'])) {
    195224            $model->attributes = $_GET['Invoice'];
    196225        }
     
    201230    }
    202231
    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     */
    204239    public function loadModel($id) {
    205240        $model = Invoice::model()->findByPk($id);
  • expert-invoice/trunk/application/models/Invoice.php

    r2080123 r2096132  
    1313use expertinvoice\application\utils\Helper;
    1414
    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 */
    1646class Invoice extends ActiveRecord {
    1747
     
    2555    private $_totalPaid;
    2656
    27    
     57    /**
     58     * @return string the associated database table name
     59     */
    2860    public function tableName() {
    2961        return '{{expertinvoice_invoice}}';
     
    3971    }
    4072
    41    
     73    /**
     74     * @return array validation rules for model attributes.
     75     */
    4276    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(
    4480            array('customerId,invoicedDate,title,dueDate', 'required'),
    4581            array('receiptNumber', 'required', 'condition' => function($model) {
     
    5086            array('amountDue, totalTax,discount,totalDiscount', 'length', 'max' => 15),
    5187            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'),
    5391        );
    5492    }
     
    6199    }
    62100
    63    
     101    /**
     102     * @return Customer            */
    64103    public function getCustomer() {
    65104        return Customer::model()->findByPk($this->customerId);
    66105    }
    67106
    68    
     107    /**
     108     * @return InvoiceItem[]
     109     */
    69110    public function getInvoiceItems() {
    70111        return InvoiceItem::model()->findAllByAttributes(array('invoiceId' => $this->getPrimaryKey()));
    71112    }
    72113
    73    
     114    /**
     115     * @return Payment[]
     116     */
    74117    public function getPayments() {
    75118        return Payment::model()->findAllByAttributes(array('invoiceId' => $this->getPrimaryKey()));
     
    80123    }
    81124
    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     */
    83136    public function invoiceSearch() {
    84137        $q = isset($_GET['q']) ? $_GET['q'] : null;
     
    106159    }
    107160
    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     */
    109172    public function quoteSearch() {
    110173        $q = isset($_GET['q']) ? $_GET['q'] : null;
     
    130193    }
    131194
    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     */
    133201    public static function model($className = __CLASS__) {
    134202        return parent::model($className);
     
    182250        $stock = null;
    183251        foreach ($stocks as $attrs) {
    184             if (isset($attrs['id'])) {
     252            if (!empty($attrs['id'])) {
    185253                $stock = InvoiceItem::model()->findByPk($attrs['id']);
    186254                if ($stock == null) {
     
    243311    }
    244312
    245    
     313    /**
     314     *
     315     * @param float $amount
     316     * @param integer $paymentMethod
     317     * @param string $transactionCode
     318     */
    246319    public function paymentMade($amount, $paymentMethod, $transactionCode) {
    247320        if (!Payment::model()->exists('transactionCode=:t AND paymentMethod=:p', array(':t' => $transactionCode, ':p' => $paymentMethod))) {
     
    268341    }
    269342
    270    
     343    /**
     344     *
     345     * @param Customer $customer
     346     * @param Template $template
     347     */
    271348    public function sendEmail($customer, $template) {
    272349        $attachment = $this->getInvoicePdf();
     
    277354    }
    278355
    279    
     356    /**
     357     *
     358     * @param type $template
     359     * @param Customer $customer
     360     * @param Invoice $model
     361     */
    280362    private function getEmailContent($template, $customer) {       
    281363        $url = $this->getViewUrl(); 
     
    292374    private function getInvoicePdf() {
    293375        require_once(FileHelper::getPluginDirPath() . '/expert-invoice/vendor/autoload.php');
     376//        use Dompdf\Dompdf;
    294377        $title = ($this->type == Invoice::TYPE_INVOICE ? 'Invoice' . $this->receiptNumber : 'Quote' . $this->quoteNumber);
    295378        $fileName = FileHelper::getTmpDir() . DIRECTORY_SEPARATOR . $title . '.pdf';
     
    299382        $options->set('defaultFont', 'Helvetica');
    300383        $options->set('isRemoteEnabled', true);
    301                 $dompdf = new \Dompdf\Dompdf($options);
     384        // instantiate and use the dompdf class
     385        $dompdf = new \Dompdf\Dompdf($options);
    302386        $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();
    306393        file_put_contents($fileName, $output);
     394//        \envoqon\App::log($fileName, envoqon\logging\Logger::LEVEL_ERROR);
    307395        return $fileName;
    308396    }
  • expert-invoice/trunk/expert-invoice.php

    r2080123 r2096132  
    66  Description: A feature-packed and flexible invoicing system.
    77  Author: Envoqon
    8   Version: 1.0
     8  Version: 1.0.1
    99  Author URI: https://www.envoqon.com/
    1010  Text Domain: expert-invoice
  • expert-invoice/trunk/readme.txt

    r2083174 r2096132  
    89897. Set up your currency, date formats, etc
    90908. 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.