function init() { parent::init(); $post_j = $this->join('post.document_id'); $post_j->hasOne('xepan\\hr\\Department', 'department_id')->sortable(true); $post_j->hasOne('xepan\\hr\\ParentPost', 'parent_post_id')->sortable(true); $post_j->hasOne('xepan\\hr\\SalaryTemplate', 'salary_template_id'); $post_j->hasOne('xepan\\hr\\LeaveTemplate', 'leave_template_id'); $post_j->addField('name')->sortable(true); $post_j->addField('in_time')->display(array('form' => 'TimePicker')); $post_j->addField('out_time')->display(array('form' => 'TimePicker')); $post_j->addField('permission_level')->enum(['Individual', 'Sibling', 'Department', 'Global'])->defaultValue('Individual'); $post_j->hasMany('xepan\\hr\\Post', 'parent_post_id', null, 'ParentPosts'); $post_j->hasMany('xepan\\hr\\Post_Email_Association', 'post_id', null, 'EmailPermissions'); $post_j->hasMany('xepan\\hr\\Employee', 'post_id', null, 'Employees'); $this->addExpression('employee_count')->set($this->refSQL('Employees')->count())->sortable(true); $this->getElement('status')->defaultValue('Active'); $this->addCondition('type', 'Post'); $this->addHook('beforeSave', [$this, 'changeEmployeeInOutTimes']); $this->addHook('beforeDelete', $this); $this->addHook('beforeDelete', [$this, 'deleteEmailAssociation']); $this->addHook('beforeSave', [$this, 'updateSearchString']); $this->addExpression('name_with_dept')->set($this->dsql()->expr('CONCAT([0]," :: ",[1])', [$this->getElement('department'), $this->getElement('name')]))->sortable(true); $this->is(['department_id|required']); }
function init() { parent::init(); $this->opp_j = $opp_j = $this->join('opportunity.document_id'); $opp_j->hasOne('xepan\\marketing\\Lead', 'lead_id')->display(['form' => 'xepan\\base\\Basic']); $opp_j->hasOne('xepan\\hr\\Employee', 'assign_to_id')->defaultValue($this->app->employee->id); $opp_j->addField('title')->sortable(true); $opp_j->addField('description')->type('text'); $opp_j->addField('fund')->type('money'); $opp_j->addField('discount_percentage')->type('int')->defaultValue(0); $opp_j->addField('closing_date')->type('date'); $opp_j->addField('narration')->type('text'); $opp_j->addField('previous_status'); $opp_j->addField('probability_percentage'); $this->addExpression('duration')->set('"TODO"'); $this->addExpression('source')->set($this->refSql('lead_id')->fieldQuery('source')); $this->addExpression('effective_name')->set(function ($m, $q) { $lead = $this->add('xepan\\marketing\\Model_Lead'); $lead->addCondition('id', $m->getElement('lead_id')); $lead->setLimit(1); return $lead->fieldQuery('effective_name'); }); $this->getElement('status')->defaultValue('Open'); $this->addCondition('type', 'Opportunity'); $this->addHook('beforeSave', [$this, 'updateSearchString']); $this->is(['closing_date|required', 'title|required']); }
function init() { parent::init(); $file_j = $this->join('file.document_id'); $file_j->hasOne('xepan\\hr\\Folder', 'folder_id'); $file_j->addField('name')->sortable(true); $file_j->addField('content')->type('text'); // $file_j->addField('content_type')->setValueList(['spreadsheet'=>'Spread Sheet','word'=>'Word','ppt'=>'PPT','todo'=>'To Do']); $file_j->hasMany('xepan\\hr\\DocumentShare', 'file_id'); $this->addHook('afterInsert', [$this, 'personalShare']); $this->addHook('beforeDelete', $this); $this->is(['name|to_trim|required']); }
function init() { parent::init(); $document_j = $this->join('tnc.document_id'); $document_j->addField('name')->sortable(true); $document_j->addField('content')->type('text')->display(['form' => 'xepan\\base\\RichText'])->defaultValue(null); $document_j->addField('is_default_for_quotation')->type('boolean'); $document_j->addField('is_default_for_sale_order')->type('boolean'); $document_j->addField('is_default_for_sale_invoice')->type('boolean'); $document_j->hasMany('xepan/commerce/QSP_Master', 'tnc_id'); $this->addCondition('type', 'TNC'); $this->is(['name|required', 'content|required']); $this->addHook('beforeSave', [$this, 'updateSearchString']); }
function init() { parent::init(); $reimbursment_j = $this->join('reimbursement.document_id'); $reimbursment_j->hasOne('xepan/hr/Employee', 'employee_id')->sortable(true); $reimbursment_j->addField('name'); // name of $reimbursment_j->hasMany('xepan\\hr\\ReimbursementDetail', 'reimbursement_id', null, 'Details'); $this->getElement('created_by'); $this->getElement('created_by_id')->system(false)->visible(true); $this->getElement('status')->defaultValue('Draft'); $this->addCondition('type', 'Reimbursement'); $this->addExpression('amount', $this->_dsql()->expr('IFNULL([0],0)', [$this->refSQL('Details')->sum('amount')])); }
function init() { parent::init(); $this->addCondition('type', 'Folder'); $folder_j = $this->join('folder.document_id'); $folder_j->hasOne('xepan\\hr\\ParentFolder', 'parent_folder_id'); $folder_j->addField('name')->sortable(true); $folder_j->hasMany('xepan\\hr\\File', 'folder_id'); $folder_j->hasMany('xepan\\hr\\folder', 'parent_folder_id', null, 'SubFolder'); $folder_j->hasMany('xepan\\hr\\DocumentShare', 'folder_id'); $this->is(['name|to_trim|required']); $this->addHook('afterInsert', [$this, 'personalShare']); $this->addHook('beforeDelete', $this); $this->addHook('beforeSave', $this); }
function init() { parent::init(); $currency_j = $this->join('currency.document_id'); $this->getElement('created_by_id')->defaultValue($this->app->employee->id); $this->getElement('status')->defaultValue('Active'); $currency_j->addField('icon'); $currency_j->addField('name')->sortable(true); $currency_j->addField('value')->sortable(true); $currency_j->addField('integer_part'); $currency_j->addField('fractional_part'); $currency_j->addField('prefix'); $currency_j->addField('postfix'); $this->addCondition('type', 'Currency'); $this->addHook('beforeSave', [$this, 'updateSearchString']); }
function init() { parent::init(); $cat_j = $this->join('category.document_id'); $cat_j->hasOne('xepan\\commerce\\ParentCategory', 'parent_category_id')->sortable(true); $cat_j->addField('name')->sortable(true); $cat_j->addField('display_sequence')->type('int')->hint('change the sequence of category, sort by decenting order')->defaultValue(0); $cat_j->addField('alt_text')->hint('set alt_text of image tag'); $cat_j->addField('description')->display(['form' => 'xepan\\base\\RichText'])->type('text'); $cat_j->addField('custom_link'); $cat_j->addField('meta_title'); $cat_j->addField('meta_description')->type('text'); $cat_j->addField('meta_keywords'); $cat_j->addField('is_website_display')->type('boolean'); $this->add('filestore\\Field_Image', 'cat_image_id')->display(['form' => 'xepan\\base\\Upload'])->from($cat_j); $cat_j->hasMany('xepan\\commerce\\Filter', 'category_id'); $cat_j->hasMany('xepan\\commerce\\CategoryItemAssociation', 'category_id'); $cat_j->hasMany('xepan\\commerce/Category', 'parent_category_id', null, 'SubCategories'); $this->addCondition('type', 'Category'); // $this->addCondition('epan_id',$this->app->epan->get('id')); $this->getElement('status')->defaultValue('Active'); // return count of saleable and and websites display item $this->addExpression('website_display_item_count')->set(function ($m, $q) { $cat_item_model = $m->add('xepan\\commerce\\Model_CategoryItemAssociation'); $cat_item_j = $cat_item_model->leftJoin('item.document_id', 'item_id'); $cat_item_j->addField('is_saleable'); $cat_item_j->addField('website_display'); $item_doc_j = $cat_item_j->join('document', 'document_id'); $item_doc_j->addField('status'); $cat_item_model->addCondition('status', 'Published'); $cat_item_model->addCondition('is_saleable', 1); $cat_item_model->addCondition('website_display', 1); $cat_item_model->addCondition('is_template', 0); $cat_item_model->addCondition('category_id', $m->getElement('id')); return $cat_item_model->count(); })->sortable(true); $this->addExpression('min_price')->set(function ($m, $q) { return $q->expr("IFNULL([0],0)", [$m->refSQL('xepan\\commerce\\CategoryItemAssociation')->setOrder('sale_price', 'asc')->setLimit(1)->fieldQuery('sale_price')]); }); $this->addExpression('max_price')->set(function ($m, $q) { return $q->expr("IFNULL([0],0)", [$m->refSQL('xepan\\commerce\\CategoryItemAssociation')->setOrder('sale_price', 'desc')->setLimit(1)->fieldQuery('sale_price')]); }); $this->addHook('beforeDelete', $this); $this->is(['name|to_trim|required|unique_in_epan', 'display_sequence|int']); $this->addHook('beforeSave', [$this, 'updateSearchString']); }
function init() { parent::init(); $cont_j = $this->join('content.document_id'); $cont_j->hasone('xepan\\marketing\\MarketingCategory', 'marketing_category_id'); $cont_j->addField('message_255')->type('text'); $cont_j->addField('message_blog')->type('text')->display(['form' => 'xepan\\base\\RichText']); $cont_j->addField('url'); $cont_j->addField('title'); $cont_j->addField('content_name'); $cont_j->addField('is_template')->type('boolean')->defaultValue(false); $cont_j->hasMany('xepan/marketing/Schedule', 'document_id'); $this->getElement('status')->defaultValue('Draft'); $this->is(['marketing_category_id|required', 'title|required']); $this->addHook('beforeDelete', [$this, 'checkExistingSchedule']); $this->addHook('beforeSave', [$this, 'updateSearchString']); }
function init() { parent::init(); $cat_j = $this->join('marketingcategory.document_id'); $cat_j->addField('name')->sortable(true); $cat_j->addField('system')->type('boolean'); $cat_j->hasMany('xepan\\marketing\\Lead_Category_Association', 'marketing_category_id'); $cat_j->hasMany('xepan\\marketing\\Campaign_Category_Association', 'marketing_category_id'); // $this->addExpression('leads_count')->set($this->refSQL('xepan\marketing\Lead_Category_Association')->count()); $this->addCondition('type', 'MarketingCategory'); $this->getElement('created_by_id')->defaultValue($this->app->employee->id); $this->addExpression('leads_count')->set(function ($m) { return $m->refSQL('xepan\\marketing\\Lead_Category_Association')->count(); })->sortable(true); $this->addHook('beforeDelete', [$this, 'checkExistingLeadCategoryAssociation']); $this->addHook('beforeDelete', [$this, 'checkExistingCampaignCategoryAssociation']); $this->addHook('beforeSave', [$this, 'updateSearchString']); }
function init() { parent::init(); $dep_j = $this->join('department.document_id'); $dep_j->addField('name')->sortable(true); $dep_j->addField('production_level')->sortable(true); $dep_j->hasMany('xepan\\hr\\Post', 'department_id', null, 'Posts'); $dep_j->hasMany('xepan\\hr\\Employee', 'department_id', null, 'Employees'); $dep_j->addField('is_system')->type('boolean')->defaultValue(false)->system(true); $dep_j->addField('is_outsourced')->type('boolean')->defaultValue(false); $this->addExpression('posts_count')->set(function ($m, $q) { return $this->add('xepan\\hr\\Model_Post', ['table_alias' => 'dept_post_count'])->addCondition('department_id', $m->getElement('id'))->count(); })->sortable(true); $this->addExpression('employee_count')->set(function ($m, $q) { return $this->add('xepan\\hr\\Model_Employee', ['table_alias' => 'dept_emp_count'])->addCondition('department_id', $m->getElement('id'))->count(); })->sortable(true); $this->getElement('status')->defaultValue('Active'); $this->addCondition('type', 'Department'); $this->addHook('beforeDelete', [$this, 'checkForPostsAndEmployees']); $this->addHook('beforeSave', [$this, 'updateSearchString']); $this->is(['name|unique_in_epan|to_trim|required', 'production_level|required?Production Level must be filled|int|>0']); }
function init() { parent::init(); $this->addCondition('type', 'SupportTicket'); $st_j = $this->join('support_ticket.document_id'); $st_j->hasOne('xepan\\base\\Contact', 'contact_id')->display(['form' => 'xepan\\base\\Basic']); $st_j->hasOne('xepan\\communication\\Communication', 'communication_id'); $st_j->addField('name')->defaultValue(rand(999, 999999))->sortable(true); $st_j->addField('uid'); $st_j->addField('from_email'); $st_j->addField('from_name'); $st_j->addField('from_raw'); $st_j->addField('from_id'); $st_j->addField('to_id'); $st_j->addField('to_raw'); $st_j->addField('cc_raw'); //->type('text'); $st_j->addField('bcc_raw'); //->type('text'); $st_j->addField('subject'); $st_j->addField('message')->type('text')->display(array('form' => 'xepan\\base\\RichText')); $st_j->addField('task_id'); $st_j->addField('priority')->enum(array('Low', 'Medium', 'High', 'Urgent'))->defaultValue('Medium')->mandatory(true); $st_j->hasMany('xepan\\crm\\Ticket_Comments', 'ticket_id', null, 'Comments'); $st_j->hasMany('xepan\\crm\\Ticket_Attachment', 'ticket_id', null, 'TicketAttachments'); $this->getElement('status')->defaultValue('Pending'); // $this->getElement('created_at')->defaultValue($this->app->now)->sortable(true); $this->add('misc/Field_Callback', 'callback_date')->set(function ($m) { if (date('Y-m-d', strtotime($m['created_at'])) == date('Y-m-d', strtotime($this->app->now))) { return date('h:i a', strtotime($m['created_at'])); } return date('M d', strtotime($m['created_at'])); }); $this->addExpression('last_comment')->set(function ($m, $q) { return $m->refSQL('Comments')->setLimit(1)->setOrder('created_at', 'desc')->fieldQuery('created_at'); })->sortable(true); $this->addExpression('assign_to_id')->set(function ($m, $q) { return $task = $m->add('xepan\\projects\\Model_Task', ['table_alias' => 'sttiass'])->addCondition('id', $m->getElement('task_id'))->fieldQuery('assign_to_id'); }); $this->addExpression('ticket_attachment')->set($this->refSQL('communication_id')->fieldQuery('attachment_count')); $this->addExpression('task_status')->set(function ($m, $q) { return $task = $m->add('xepan\\projects\\Model_Task')->addCondition('id', $m->getField('task_id'))->fieldQuery('status'); }); $this->addExpression('image_avtar')->set(function ($m, $q) { return $q->expr('[0]', [$m->refSQL('contact_id')->fieldQuery('image')]); }); $this->addHook('afterLoad', function ($m) { $this['from_raw'] = json_decode($m['from_raw'], true); $this['to_raw'] = json_decode($m['to_raw'], true); // var_dump($this['to_raw']); // exit; $this['cc_raw'] = json_decode($m['cc_raw'], true); $this['bcc_raw'] = json_decode($m['bcc_raw'], true); $this['subject'] = $m['subject'] ?: '(no subject)'; }); $this->addHook('beforeSave', function ($m) { if (is_array($m['to_raw'])) { $m['to_raw'] = json_encode($m['to_raw']); } if (is_array($m['from_raw'])) { $m['from_raw'] = json_encode($m['from_raw']); } if (is_array($m['cc_raw'])) { $m['cc_raw'] = json_encode($m['cc_raw']); } if (is_array($m['bcc_raw'])) { $m['bcc_raw'] = json_encode($m['bcc_raw']); } $m['subject'] = $m['subject'] ?: "(no subject)"; }); $this->addExpression('contact_name')->set($this->refSQL('contact_id')->fieldQuery('name')); $this->addHook('beforeDelete', [$this, 'deleteComments']); $this->addHook('beforeSave', [$this, 'updateSearchString']); }
function init() { parent::init(); $job_j = $this->join('jobcard.document_id'); $job_j->hasOne('xepan\\hr\\Department', 'department_id')->sortable(true); $job_j->hasOne('xepan\\production\\ParentJobcard', 'parent_jobcard_id')->defaultValue(0)->sortable(true); $job_j->hasOne('xepan\\production\\OutsourceParty', 'outsourceparty_id')->sortable(true); //it show current department $job_j->hasOne('xepan\\commerce\\QSP_Detail', 'order_item_id')->sortable(true); $job_j->hasOne('xepan\\hr\\Employee', 'assign_to_id')->sortable(true); $job_j->addField('due_date')->type('datetime')->sortable(true); $job_j->hasMany('xepan\\production\\Jobcard_Detail', 'jobcard_id'); $job_j->hasMany('xepan\\production\\Jobcard', 'parent_jobcard_id', null, 'SubJobcard'); $job_j->hasMany('xepan\\commerce\\Store_Transaction', 'jobcard_id'); $this->addCondition('type', 'Jobcard'); $this->addHook('beforeDelete', [$this, 'checkExistingRelatedTransaction']); $this->addExpression('order_no')->set(function ($m, $q) { $sales_order = $m->add('xepan/commerce/Model_SalesOrder', ['table_alias' => 'order_no']); $order_detail_j = $sales_order->join('qsp_detail.qsp_master_id'); $order_detail_j->addField('details_id', 'id'); $sales_order->addCondition('details_id', $m->getElement('order_item_id')); return $sales_order->fieldQuery('document_no'); })->sortable(true); $this->addExpression('qsp_item_narration')->set(function ($m, $q) { return $m->refSQL('order_item_id')->fieldQuery('narration'); }); $this->addExpression('order_document_id')->set(function ($m, $q) { $sales_order = $m->add('xepan/commerce/Model_SalesOrder', ['table_alias' => 'order_no']); $order_detail_j = $sales_order->join('qsp_detail.qsp_master_id'); $order_detail_j->addField('details_id', 'id'); $sales_order->addCondition('details_id', $m->getElement('order_item_id')); return $sales_order->fieldQuery('id'); })->sortable(true); $this->addExpression('customer_id')->set(function ($m, $q) { return $m->refSQL('order_item_id')->fieldQuery('customer_id'); })->sortable(true); $this->addExpression('customer_name')->set(function ($m, $q) { return $m->refSQL('order_item_id')->fieldQuery('customer'); })->sortable(true); $this->addExpression('order_item_name')->set(function ($m, $q) { return $m->refSQL('order_item_id')->fieldQuery('name'); })->sortable(true); $this->addExpression('order_item_quantity')->set(function ($m, $q) { return $m->refSQL('order_item_id')->fieldQuery('quantity'); })->sortable(true); $this->addExpression('item_id')->set(function ($m, $q) { return $m->refSQL('order_item_id')->fieldQuery('item_id'); })->sortable(true); $this->addExpression('toreceived')->set(function ($m, $q) { $to_received = $m->refSQL('xepan\\production\\Jobcard_Detail')->addCondition('status', 'ToReceived')->sum('quantity'); return $q->expr("IFNULL ([0], 0)", [$to_received]); })->sortable(true); $this->addExpression('forwarded')->set(function ($m, $q) { $forwarded = $m->refSQL('xepan\\production\\Jobcard_Detail')->addCondition('status', 'Forwarded')->sum('quantity'); return $q->expr("IFNULL([0],0)", [$forwarded]); })->sortable(true); $this->addExpression('receivedbynext')->set(function ($m, $q) { $forwarded = $m->refSQL('xepan\\production\\Jobcard_Detail')->addCondition('status', 'ReceivedByNext')->sum('quantity'); return $q->expr("IFNULL([0],0)", [$forwarded]); })->sortable(true); $this->addExpression('pendingbynext')->set(function ($m, $q) { return $q->expr(" IFNULL ([0] - [1],0)", [$m->getElement('forwarded'), $m->getElement('receivedbynext')]); }); $this->addExpression('receivedbydispatch')->set(function ($m, $q) { return $q->expr("IFNULL([0],0)", [$m->refSQL('xepan\\commerce\\Store_Transaction')->sum('received')]); })->sortable(true); $this->addExpression('pendingbydispatch')->set(function ($m, $q) { return $q->expr("IFNULL([0],0)", [$m->refSQL('xepan\\commerce\\Store_Transaction')->sum('toreceived')]); })->sortable(true); $this->addExpression('completed')->set(function ($m, $q) { $completed = $m->refSQL('xepan\\production\\Jobcard_Detail')->addCondition('status', 'Completed')->sum('quantity'); return $q->expr("IFNULL([0], 0)", [$completed]); })->sortable(true); $this->addExpression('dispatched')->set(function ($m, $q) { $dispatched = $m->refSQL('xepan\\production\\Jobcard_Detail')->addCondition('status', 'Dispatched')->sum('quantity'); return $q->expr("IFNULL ([0], 0)", [$dispatched]); }); $this->addExpression('processing')->set(function ($m, $q) { $processing = $m->refSQL('xepan\\production\\Jobcard_Detail')->addCondition('status', 'Received')->sum('quantity'); return $q->expr("IFNULL(([0] - IFNULL([1],0)),0)", [$processing, $m->getElement('completed')]); })->sortable(true); $this->addExpression('days_elapsed')->set(function ($m, $q) { // return "'Todo'"; $date = $m->add('\\xepan\\base\\xDate'); $diff = $date->diff(date('Y-m-d H:i:s', strtotime($m['created_at'])), date('Y-m-d H:i:s', strtotime($m['due_date'] ? $m['due_date'] : $this->app->today)), 'Days'); return "'" . $diff . "'"; })->sortable(true); $this->addHook('beforeDelete', $this); $this->addHook('beforeSave', [$this, 'updateSearchString']); }
function init() { parent::init(); $qsp_master_j = $this->join('qsp_master.document_id'); $qsp_master_j->hasOne('xepan/base/Contact', 'contact_id')->sortable(true); $qsp_master_j->hasOne('xepan/accounts/Currency', 'currency_id'); $qsp_master_j->hasOne('xepan/accounts/Ledger', 'nominal_id'); $qsp_master_j->hasOne('xepan/commerce/TNC', 'tnc_id')->defaultValue(null); $qsp_master_j->hasOne('xepan/commerce/PaymentGateway', 'paymentgateway_id')->defaultValue(null); $qsp_master_j->hasOne('xepan\\production\\OutsourceParty', 'outsource_party_id'); $qsp_master_j->hasOne('xepan\\base\\Country', 'billing_country_id')->display(array('form' => 'xepan\\commerce\\DropDown')); $qsp_master_j->hasOne('xepan\\base\\State', 'billing_state_id')->display(array('form' => 'xepan\\commerce\\DropDown')); $qsp_master_j->hasOne('xepan\\base\\Country', 'shipping_country_id')->display(array('form' => 'xepan\\commerce\\DropDown')); $qsp_master_j->hasOne('xepan\\base\\State', 'shipping_state_id')->display(array('form' => 'xepan\\commerce\\DropDown')); //Related QSP Master $qsp_master_j->hasOne('xepan\\commerce\\RelatedQspMaster', 'related_qsp_master_id')->defaultValue('Null'); $qsp_master_j->addField('document_no')->sortable(true); $this->addExpression('document_no_number')->set('CAST(document_no AS decimal)')->sortable(true); $qsp_master_j->addField('billing_address'); $qsp_master_j->addField('billing_city'); $qsp_master_j->addField('billing_pincode'); $qsp_master_j->addField('shipping_address'); $qsp_master_j->addField('shipping_city'); $qsp_master_j->addField('shipping_pincode'); $qsp_master_j->addField('is_shipping_inclusive_tax')->type('boolean')->defaultValue(false); $qsp_master_j->addField('is_express_shipping')->type('boolean'); $qsp_master_j->addField('from')->hint('Offline,Online etc')->defaultValue('Offline'); //Total Amount: calculate sum all item field amount_excluding_tax $this->addExpression('total_amount')->set(function ($m, $q) { $details = $m->refSQL('Details'); return $details->sum('amount_excluding_tax'); })->type('money'); //Total Item amount Sum including tax $this->addExpression('gross_amount')->set(function ($m, $q) { $details = $m->refSQL('Details'); return $q->expr("round([0],2)", [$details->sum('total_amount')]); })->type('money'); $qsp_master_j->addField('discount_amount')->defaultValue(0)->type('money'); $this->addExpression('tax_amount')->set(function ($m, $q) { $details = $m->refSQL('Details'); return $q->expr("[0]", [$details->sum('tax_amount')]); })->type('money'); $this->addExpression('net_amount')->set(function ($m, $q) { return $q->expr('round( ([0] - [1] - IFNULL([2],0)), 2 )', [$m->getElement('gross_amount'), $m->getElement('discount_amount'), $m->getElement('round_amount')]); })->type('money'); $qsp_master_j->addField('due_date')->type('datetime')->defaultValue(null); $qsp_master_j->addField('priority_id'); $qsp_master_j->addField('narration')->type('text'); $qsp_master_j->addField('exchange_rate')->defaultValue(1); $qsp_master_j->addField('tnc_text')->type('text')->defaultValue(''); $qsp_master_j->addField('round_amount')->defaultValue('0.00'); $this->addExpression('net_amount_self_currency')->set(function ($m, $q) { return $q->expr('([0]*[1])', [$m->getElement('net_amount'), $m->getElement('exchange_rate')]); })->type('money'); $qsp_master_j->addField('transaction_reference'); $qsp_master_j->addField('transaction_response_data'); $this->getElement('status')->defaultValue('Draft'); $qsp_master_j->hasMany('xepan\\commerce\\QSP_Detail', 'qsp_master_id', null, 'Details'); $qsp_master_j->hasMany('xepan\\commerce\\QSP_Master', 'related_qsp_master_id', null, 'RelatedQSP'); //Currency Icon $this->addExpression('invoice_currency_icon', function ($m, $q) { return $m->refSQL('currency_id')->fieldQuery('icon'); }); $this->addHook('beforeDelete', [$this, 'deleteDetails']); $this->addHook('beforeSave', [$this, 'updateTnCTextifChanged']); $this->addHook('beforeSave', [$this, 'updateSearchString']); $this->addHook('beforeSave', [$this, 'updateRoundAmount']); $this->is(['contact_id|required', 'billing_address|required', 'billing_country_id|required', 'billing_state_id|required', 'billing_city|required', 'billing_pincode|required', 'due_date|date_after|created_at', 'document_no|required|number|unique_in_epan_for_type', 'currency_id|required', 'exchange_rate|number|gt|0']); }
function init() { parent::init(); $this->getElement('created_by_id')->defaultValue(@$this->app->employee->id); $item_j = $this->join('item.document_id'); $item_j->hasOne('xepan\\base\\Contact', 'designer_id')->defaultValue(0); $item_j->hasOne('xepan\\commerce\\Model_Item_Template', 'duplicate_from_item_id')->defaultValue(0); $item_j->addField('name')->mandatory(true)->sortable(true); $item_j->addField('sku')->PlaceHolder('Insert Unique Referance Code')->caption('Code')->hint('Insert Unique Referance Code')->mandatory(true); $item_j->addField('display_sequence')->hint('descending wise sorting'); $item_j->addField('description')->type('text')->display(array('form' => 'xepan\\base\\RichText')); $item_j->addField('original_price')->type('money')->mandatory(true)->defaultValue(0); $item_j->addField('sale_price')->type('money')->mandatory(true)->defaultValue(0)->sortable(true); $item_j->addField('expiry_date')->type('date')->defaultValue(null); $item_j->addField('minimum_order_qty')->type('int')->defaultValue(1); $item_j->addField('maximum_order_qty')->type('int')->defaultValue(null); $item_j->addField('qty_unit')->defaultValue(null); $item_j->addField('qty_from_set_only')->type('boolean')->defaultValue(true); // Item renewable fields $item_j->addField('is_renewable')->type('boolean')->defaultValue(0); $item_j->addField('remind_to')->display(['form' => 'xepan\\base\\DropDown'])->setValueList(['Both' => 'Both', 'Customer' => 'Customer', 'Admin' => 'Admin']); $item_j->addField('renewable_value')->type('number'); $item_j->addField('renewable_unit')->setValueList(['day' => 'Days', 'months' => 'Months']); //Item Allow Optins $item_j->addField('is_party_publish')->type('boolean')->hint('Freelancer Item Design/Template to be Approved')->defaultValue(false); $item_j->addField('is_saleable')->type('boolean')->hint('Make Item Becomes Saleable')->defaultValue(false); $item_j->addField('is_allowuploadable')->type('boolean')->hint('on website customer can upload a degin for designable item')->defaultValue(false); $item_j->addField('is_purchasable')->type('boolean')->hint('item display only at purchase Order/Invoice')->defaultValue(false); //Item Stock Options // $item_j->addField('available_stock')->type('boolean')->hint('Stock Availability '); $item_j->addField('maintain_inventory')->type('boolean')->hint('Manage Inventory ')->defaultValue(false); $item_j->addField('allow_negative_stock')->type('boolean')->hint('show item on website apart from stock is available or not')->defaultValue(false); $item_j->addField('is_dispatchable')->type('boolean')->hint('show item on website apart from stock is is dispatchable or not')->defaultValue(false); $item_j->addField('negative_qty_allowed')->type('boolean')->hint('allow the negative stock until this quantity')->defaultValue(false); $item_j->addField('is_visible_sold')->type('boolean')->hint('display item on website after out of stock/all sold')->defaultValue(false); $item_j->addField('is_servicable')->type('boolean')->defaultValue(false); $item_j->addField('is_productionable')->type('boolean')->hint('used in Production')->defaultValue(false); $item_j->addField('website_display')->type('boolean')->hint('Show on Website')->defaultValue(false); $item_j->addField('is_downloadable')->type('boolean')->defaultValue(false); $item_j->addField('is_rentable')->type('boolean')->defaultValue(false); $item_j->addField('is_designable')->type('boolean')->hint('item become designable and customer customize the design')->defaultValue(false); $item_j->addField('is_template')->type('boolean')->hint('blueprint/layout of designable item')->defaultValue(false); $item_j->addField('is_attachment_allow')->type('boolean')->hint('by this option you can attach the item information pdf/doc etc. to be available on website')->defaultValue(false); $item_j->addField('warranty_days')->type('int')->defaultValue(null); $item_j->addField('weight')->defaultValue(0); //Item Display Options $item_j->addField('show_detail')->type('boolean'); $item_j->addField('show_price')->type('boolean'); //Marked $item_j->addField('is_new')->type('boolean')->caption('New'); $item_j->addField('is_feature')->type('boolean')->caption('Featured'); $item_j->addField('is_mostviewed')->type('boolean')->caption('Most Viewed'); //Enquiry Send To $item_j->addField('is_enquiry_allow')->type('boolean')->hint('display enquiry form at item detail on website')->defaultValue(false); $item_j->addField('enquiry_send_to_admin')->type('boolean')->hint('send a copy of enquiry form to admin')->defaultValue(false); $item_j->addField('item_enquiry_auto_reply')->type('boolean')->caption('Item Enquiry Auto Reply')->defaultValue(false); //Item Comment Options $item_j->addField('is_comment_allow')->type('boolean')->defaultValue(false); $item_j->addField('comment_api')->setValueList(array('disqus' => 'Disqus'))->defaultValue(''); //Item Other Options $item_j->addField('add_custom_button')->type('boolean'); $item_j->addField('custom_button_label')->defaultValue(null); $item_j->addField('custom_button_url')->placeHolder('subpage name like registration etc.'); // Item WaterMark // $item_j->add('xepan/filestore/Field_Image','watermark_image_id'); $item_j->addField('watermark_text')->type('text')->defaultValue(''); $item_j->addField('watermark_position')->enum(array('TopLeft', 'TopRight', 'BottomLeft', 'BottomRight', 'Center', 'Left Diagonal', 'Right Diagonal'))->defaultValue('Center'); $item_j->addField('watermark_opacity')->defaultValue(50); //Item SEO $item_j->addField('meta_title')->defaultValue(null); $item_j->addField('meta_description')->type('text')->defaultValue(null); $item_j->addField('tags')->type('text')->PlaceHolder('Comma Separated Value')->defaultValue(null); //Item Designs $item_j->addField('designs')->type('text')->hint('used for internal, design saved')->defaultValue(null); //others $item_j->addField('terms_and_conditions')->type('text')->defaultValue(null); // $item_j->addField('duplicate_from_item_id')->hint('internal used saved its parent')->defaultValue(null); $item_j->addField('upload_file_label')->type('text')->hint('comma separated multiple file name, ex. file_name_1:mandatory, file_name_2, file_name_3:mandatory, file_name_4'); $item_j->addField('item_specific_upload_hint')->type('text')->hint('Hint for upload images')->defaultValue(null)->display(array('form' => 'xepan\\base\\RichText')); $item_j->addField('upload_file_group'); $item_j->addField('to_customer_id')->hint('Specific to customer/organization')->defaultValue(null); $item_j->addField('quantity_group'); $this->addCondition('type', 'Item'); $this->getElement('status')->defaultValue('UnPublished'); //Quantity set condition just for relation $item_j->hasMany('xepan\\commerce\\Item_Quantity_Set', 'item_id'); $item_j->hasMany('xepan\\commerce\\Item_CustomField_Association', 'item_id'); $item_j->hasMany('xepan\\commerce\\Item_Department_Association', 'item_id', null); //Category Item Association $item_j->hasMany('xepan\\commerce\\CategoryItemAssociation', 'item_id'); //Member Design $item_j->hasMany('xepan\\commerce\\Item_Template_Design', 'item_id'); $this->hasMany('xepan\\commerce\\Store_TransactionRow', 'item_id', null, 'StoreTransactionRows'); $this->hasMany('xepan\\commerce\\QSP_Detail', 'item_id', null, 'QSPDetail'); $item_j->hasMany('xepan\\commerce\\Item_Image', 'item_id', null, 'ItemImages'); $item_j->hasMany('xepan\\commerce\\Item_Taxation_Association', 'item_id', null, 'Tax'); $item_j->hasMany('xepan\\commerce\\Item_Shipping_Association', 'item_id'); //Stock Availability $this->addExpression('available_stock')->set(function ($m) { return "'0'"; }); //Image $this->addExpression('first_image')->set(function ($m) { return $m->refSQL('ItemImages')->setLimit(1)->fieldQuery('thumb_url'); }); //Total Sales And Total Orders $this->addExpression('total_orders')->set(function ($m, $q) { $qsp_details = $m->add('xepan\\commerce\\Model_QSP_Detail', ['table_alias' => 'total_orders']); $qsp_details->addExpression('document_type')->set($qsp_details->refSQL('qsp_master_id')->fieldQuery('type')); $qsp_details->addCondition('document_type', 'SalesOrder'); $qsp_details->addCondition('item_id', $q->getField('id')); return $qsp_details->_dsql()->del('fields')->field($q->expr('SUM([0])', [$qsp_details->getElement('quantity')])); })->sortable(true); // $this->debug(); $this->addExpression('total_sales')->set(function ($m, $q) { $qsp_details = $m->add('xepan\\commerce\\Model_QSP_Detail', ['table_alias' => 'total_sales']); $qsp_details->addExpression('document_type')->set($qsp_details->refSQL('qsp_master_id')->fieldQuery('type')); $qsp_details->addCondition('document_type', 'SalesInvoice'); $qsp_details->addCondition('item_id', $q->getField('id')); return $qsp_details->_dsql()->del('fields')->field($q->expr('SUM([0])', [$qsp_details->getElement('quantity')])); }); $this->addHook('beforeDelete', $this); $this->addHook('beforeSave', [$this, 'updateSearchString']); $this->is(['name|to_trim|required', 'sku|to_trim|required|unique_in_epan', 'display_sequence|int', 'original_price|number', 'sale_price|number|>=0', 'minimum_order_qty|number|>0']); }
function init() { parent::init(); $camp_j = $this->join('campaign.document_id'); $camp_j->addField('title'); $camp_j->addField('schedule')->defaultValue('[]'); $camp_j->addField('starting_date')->type('date'); $camp_j->addField('ending_date')->type('date'); $camp_j->addField('campaign_type')->enum(['subscription', 'campaign']); $camp_j->hasMany('xepan\\marketing\\Schedule', 'campaign_id'); $camp_j->hasMany('xepan\\marketing\\Campaign_Category_Association', 'campaign_id'); $camp_j->hasMany('xepan\\marketing\\Campaign_SocialUser_Association', 'campaign_id'); $this->addCondition('type', 'Campaign'); $this->getElement('status')->defaultValue('Draft'); $this->addExpression('total_visitor')->set(function ($m, $q) { return $this->add('xepan\\marketing\\Model_LandingResponse')->addCondition('campaign_id', $q->getField('id'))->count(); }); $this->addExpression('started_since')->set(function ($m, $q) { return $m->dsql()->expr("DATEDIFF([1],[0])", [$m->getElement('starting_date'), $this->app->today]); }); $this->addExpression('remaining_duration')->set(function ($m, $q) { return $m->dsql()->expr("DATEDIFF([0],[1])", [$m->getElement('ending_date'), $this->app->today]); }); // social posts posted $this->addExpression('social_postings_posted_count')->set(function ($m, $q) { return $this->add('xepan\\marketing\\Model_SocialPosters_Base_SocialPosting')->addCondition('campaign_id', $m->getElement('id'))->addCondition('posted_on', '<>', null)->count(); }); // newsletter posted $this->addExpression('newsletter_sent_count')->set(function ($m, $q) { $comm_m = $m->add('xepan\\communication\\Model_Communication'); $comm_m->join('schedule', 'related_id')->addField('campaign_id'); return $comm_m->addCondition('campaign_id', $q->getField('id'))->count(); }); // newsletter and social posts posted $this->addExpression('total_combined_postings_done')->set(function ($m, $q) { return $m->dsql()->expr("([0]+[1])", [$m->getElement('social_postings_posted_count'), $m->getElement('newsletter_sent_count')]); }); $this->addExpression('newsletter_remaining')->set(function ($m, $q) { return $this->add('xepan\\marketing\\Model_Campaign_ScheduledNewsletters')->addCondition('lead_campaing_id', $q->getField('id'))->addCondition('is_already_sent', 0)->count(); }); $this->addExpression('social_post_remaining')->set(function ($m, $q) { return $this->add('xepan\\marketing\\Model_Schedule')->addCondition('campaign_id', $m->getElement('id'))->addCondition('posted_on', null)->addCondition('content_type', 'SocialPost')->count(); }); // newsletter and social post combined {remaining} $this->addExpression('total_remaining')->set(function ($m, $q) { return $q->expr('[0]+[1]', [$m->getElement('social_post_remaining'), $m->getElement('newsletter_remaining')]); }); $this->addExpression('total')->set(function ($m, $q) { return $m->dsql()->expr("([0]+[1])", [$m->getElement('total_combined_postings_done'), $m->getElement('total_remaining')]); }); $this->addExpression('completed_percentage')->set(function ($m, $q) { return $m->dsql()->expr("IFNULL(ROUND(([0]/([0]+[1]))*100,0),0)", [$m->getElement('total_combined_postings_done'), $m->getElement('total_remaining')]); }); $this->addHook('beforeSave', $this); $this->addHook('beforeSave', [$this, 'updateSearchString']); $this->addHook('beforeDelete', [$this, 'checkExistingCampaignCategoryAssociation']); $this->addHook('beforeDelete', [$this, 'checkExistingCampaignSocialUserAssociation']); $this->addHook('beforeDelete', [$this, 'checkExistingSchedule']); $this->addHook('beforeDelete', [$this, 'checkExistingLandingResponses']); $this->addHook('beforeDelete', [$this, 'checkExistingSocialPostings']); }