Your IP : 216.73.216.79


Current Path : /var/www/html/dyna-crm/models/
Upload File :
Current File : /var/www/html/dyna-crm/models/Invoice2.php

<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "invoice".
 *
 * @property int $id
 * @property string $uuid
 * @property string $doc_dt
 * @property string $invoice_no
 * @property string $type
 * @property string $do_no
 * @property int $com_id
 * @property string $term
 * @property int $customer_id
 * @property string $customer_name
 * @property string $customer_address1
 * @property string $customer_address2
 * @property string $customer_postcode
 * @property string $customer_city
 * @property string $customer_state
 * @property string $customer_pic
 * @property string $customer_phone
 * @property string $created_dt
 * @property int $created_by
 * @property string $updated_dt
 * @property int $updated_by
 */
class Invoice2 extends \yii\db\ActiveRecord {

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return 'invoice';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['uuid', 'com_id', 'customer_name', 'customer_address1', 'customer_postcode', 'customer_city', 'customer_state', 'customer_pic', 'customer_phone', 'doc_dt', 'sales_pic'], 'required'],
            [['doc_dt', 'created_dt', 'updated_dt', 'payment_status', 'tax', 'remarks', 'payment_due', 'grandtotal', 'paid_dt'], 'safe'],
            [['com_id', 'customer_id', 'created_by', 'updated_by'], 'integer'],
            [['invoice_no', 'type', 'do_no', 'term', 'customer_name', 'customer_address1', 'customer_address2', 'customer_city', 'customer_state', 'customer_pic', 'customer_phone'], 'string', 'max' => 255],
            [['customer_postcode'], 'string', 'max' => 10],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'uuid' => 'Uuid',
            'doc_dt' => 'Invoice Date',
            'invoice_no' => 'Invoice No',
            'type' => 'Type',
            'do_no' => 'Do No',
            'com_id' => 'Company',
            'term' => 'Term',
            'customer_id' => 'Customer',
            'customer_name' => 'Customer Name',
            'customer_address1' => 'Customer Address1',
            'customer_address2' => 'Customer Address2',
            'customer_postcode' => 'Postcode',
            'customer_city' => 'City',
            'customer_state' => 'State',
            'customer_pic' => 'Contact Person',
            'customer_phone' => 'Contact Number',
            'created_dt' => 'Created Dt',
            'created_by' => 'Created By',
            'updated_dt' => 'Updated Dt',
            'updated_by' => 'Updated By',
            'payment_status' => 'Payment Status',
            'tax' => 'Tax',
            'remarks' => 'Remarks',
            'payment_due' => 'Payment Due',
            'sales_pic' => 'Sales Person'
        ];
    }

    public function calcpaymentdue($invoice_date, $invoice_term) {
        $start_date = date("Y-m-d", strtotime($invoice_date));
        $invoice_term_arr = explode('_', $invoice_term);
        if ($invoice_term_arr[0] == 'end') {
            $start_date = date("Y-m-t", strtotime($invoice_date));
        }
        return date('Y-m-d', strtotime($start_date . ' + ' . $invoice_term_arr[1] . ' days'));
    }

}