Пример #1
0
 public function getTotalChargesNDiscount($service_type, $service_id, $customer_id)
 {
     $discount = CustomerDiscount::model()->findByAttributes(array('service_type' => $service_type, 'service_id' => $service_id, 'customer_id' => $customer_id));
     if (!$discount instanceof CustomerDiscount) {
         return array($this->charges, 0);
     } else {
         return array($this->charges - $this->charges * $discount->discount / 100, $discount->discount);
     }
 }
Пример #2
0
 protected function renderDataCellContent($row, $data)
 {
     $model = CustomerDiscount::model()->findByAttributes(array('customer_id' => $this->customer_id, 'service_id' => $data->id));
     if (!$model instanceof CustomerDiscount) {
         $model = new CustomerDiscount();
     }
     $options = $this->checkBoxHtmlOptions;
     $options['name'] = str_replace('CustomerDiscount', 'CustomerDiscount[' . $row . ']', CHtml::activeName($model, $this->forAttribute));
     $options['class'] = $this->id;
     echo CHtml::activeCheckBox($model, $this->forAttribute, $options);
 }
Пример #3
0
<h4 class="ui-box-header ui-corner-all">
	Discount List for customer <?php 
echo $customer->name;
?>
</h4>
<br />
<?php 
$form = $this->beginWidget('CActiveForm', array('id' => 'customer-discount--form', 'enableAjaxValidation' => false, 'enableClientValidation' => true, 'clientOptions' => array('validateOnSubmit' => true)));
?>
<div class="grid">
	<?php 
$this->widget('zii.widgets.grid.CGridView', array('id' => 'discount-grid', 'filter' => $services, 'dataProvider' => $services->search(), 'htmlOptions' => array('class' => 'hastable'), 'columns' => array(array('header' => 'Product Service Code', 'type' => 'raw', 'value' => '$data->productService->code', 'name' => 'search_code'), array('header' => 'Carrier', 'type' => 'raw', 'value' => '$data->rateCompanyService->rateCompany->name'), array('header' => 'Company Service Name', 'type' => 'raw', 'value' => '$data->rateCompanyService->name'), array('header' => 'Vendor Discount (%)', 'type' => 'raw', 'value' => function ($data, $row) use($customer) {
    return CustomerDiscount::model()->getTextField($customer->id, $data->id, $row, 'vendor_discount', $data->rateCompanyService->rateCompany->id, TRUE, 3);
}), array('header' => 'discount invoice (%)', 'type' => 'raw', 'value' => function ($data, $row) use($customer) {
    return CustomerDiscount::model()->getDiscountTextField($customer->id, $data->id, $row);
}), array('header' => 'Harga invoice', 'type' => 'raw', 'value' => function ($data, $row) use($customer) {
    return CustomerDiscount::model()->getTextField($customer->id, $data->id, $row, 'harga_invoice', $data->rateCompanyService->rateCompany->id);
}), array('header' => 'discount api (%)', 'type' => 'raw', 'value' => function ($data, $row) use($customer) {
    return CustomerDiscount::model()->getTextField($customer->id, $data->id, $row, 'discount_api', $data->rateCompanyService->rateCompany->id, TRUE, 3);
}), array('header' => 'Harga api', 'type' => 'raw', 'value' => function ($data, $row) use($customer) {
    return CustomerDiscount::model()->getTextField($customer->id, $data->id, $row, 'harga_api', $data->rateCompanyService->rateCompany->id);
}), array('header' => 'Use rate', 'class' => 'CFCheckBoxColumn', 'selectableRows' => 2, 'customer_id' => $customer->id, 'checkBoxHtmlOptions' => array('name' => 'CustomerDiscount'), 'forAttribute' => 'use_rate'), array('header' => 'Show in API', 'class' => 'CFCheckBoxColumn', 'selectableRows' => 2, 'customer_id' => $customer->id, 'checkBoxHtmlOptions' => array('name' => 'CustomerDiscount'), 'forAttribute' => 'show_in_api'))));
?>
</div>
<?php 
echo CHtml::submitButton('Save');
?>

<?php 
$this->endWidget();
Пример #4
0
 public function actionGetRates()
 {
     $inquiry = new InquiryForm('api-rate');
     $req = Yii::app()->request;
     $inquiryMap = new CMap();
     $inquiryMap->add('shipper_country', $req->getQuery('shipper_country'));
     $inquiryMap->add('shipper_city', $req->getQuery('shipper_city'));
     $inquiryMap->add('shipper_postal', $req->getQuery('shipper_postal'));
     $inquiryMap->add('receiver_country', $req->getQuery('receiver_country'));
     $inquiryMap->add('receiver_city', $req->getQuery('receiver_city'));
     $inquiryMap->add('receiver_postal', $req->getQuery('receiver_postal'));
     $inquiryMap->add('package_weight', $req->getQuery('package_weight'));
     $inquiry->setAttributes($inquiryMap->toArray());
     if (!$inquiry->validate()) {
         echo CJSON::encode($this->statusError($inquiry->getErrors()));
         Yii::app()->end();
     }
     /**
      * cek for customer rate management
      */
     $customer_id = null;
     $allow_api = array();
     if ($this->token instanceof Token) {
         $customer_id = $this->token->customer_id;
         $customer_rates = CustomerDiscount::model()->findAllByAttributes(array('customer_id' => $this->token->customer_id, 'show_in_api' => 1));
         foreach ($customer_rates as $cus_rate) {
             array_push($allow_api, $cus_rate->service_id);
         }
     }
     /**
      * for international service
      */
     if (strtolower($inquiry->receiver_country) != 'indonesia') {
         $country = ZoneInternational::model()->findByAttributes(array('country' => strtolower($inquiry->receiver_country)));
         if (!$country instanceof ZoneInternational) {
             echo CJSON::encode($this->statusError('There is no available service for the country you\'re requested'));
             Yii::app()->end();
         }
         $rates = RateInternational::getServicesAPI($inquiry->package_weight, $country->zone, $country->transit_time, $customer_id, $allow_api);
         $product = 'International';
         if (count($rates) == 0) {
             echo CJSON::encode($this->statusError('No Available Service'));
             Yii::app()->end();
         }
         echo CJSON::encode($this->statusSuccess(array('zone' => $country->zone, 'service_type' => 'International', 'rates' => $rates)));
         Yii::app()->end();
     } else {
         $routing = IntraCityRouting::model()->findByAttributes(array('postcode' => $inquiry->receiver_postal));
         if ($routing instanceof IntraCityRouting) {
             $area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
             if (!$area) {
                 echo CJSON::encode($this->statusError('No Available Service'));
                 Yii::app()->end();
             }
             $rates1 = RateCity::getCityRateAPI(ProductService::ProductCityCourier, $routing->code, $inquiry->package_weight, $customer_id, $allow_api);
             $rates2 = RateDomestic::getServiceListAPI(1, $area['district_id'], $area['zone_id'], $inquiry->package_weight, ProductService::ProductCityCourier, $customer_id, $allow_api);
             $rates = array_merge($rates1, $rates2);
             $product = 'City Courier';
             if (count($rates) == 0) {
                 echo CJSON::encode($this->statusError('No Available Service'));
                 Yii::app()->end();
             }
         } else {
             $area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
             if (!$area) {
                 echo CJSON::encode($this->statusError('No Available Service'));
                 Yii::app()->end();
             }
             $rates = RateDomestic::getServiceListAPI(1, $area['district_id'], $area['zone_id'], $inquiry->package_weight, ProductService::ProductDomestic, $customer_id, $allow_api);
             $product = 'Domestic';
             if (count($rates) == 0) {
                 echo CJSON::encode($this->statusError('No Available Service'));
                 Yii::app()->end();
             }
         }
         echo CJSON::encode($this->statusSuccess(array('zone_id' => $area['zone_id'], 'service_type' => $product, 'rates' => $rates)));
         Yii::app()->end();
     }
 }
 public function actionDiscount($id)
 {
     $customer = $this->loadModel($id);
     $services = new ServiceDetail('search');
     $services->unsetAttributes();
     // clear any default values
     if (isset($_GET['ServiceDetail'])) {
         $services->attributes = $_GET['ServiceDetail'];
     }
     if (isset($_POST['CustomerDiscount'])) {
         foreach ($_POST['CustomerDiscount'] as $key => $data) {
             if (isset($data['id'])) {
                 $model = CustomerDiscount::model()->findByPk($data['id']);
             } else {
                 $model = new CustomerDiscount();
             }
             $model->setAttributes($data);
             $model->save();
         }
     }
     $this->render('discount', array('services' => $services, 'customer' => $customer));
 }
 public function actionGetRates()
 {
     if (Yii::app()->request->isAjaxRequest && isset($_GET['Cek'])) {
         $inquiry = new InquiryForm('api-rate');
         $inquiry->setAttributes($_GET['Cek']);
         $customer_id = null;
         $use_rate = array();
         $rates = array();
         if (isset($_GET['customer_id']) && is_numeric($_GET['customer_id'])) {
             $customer_id = $_GET['customer_id'];
             $customer = Customer::model()->findByPk($customer_id);
             if ($customer instanceof Customer) {
                 $customer_id = $customer->id;
                 $customer_rates = CustomerDiscount::model()->findAllByAttributes(array('customer_id' => $customer->id, 'use_rate' => 1));
                 foreach ($customer_rates as $cus_rate) {
                     array_push($use_rate, $cus_rate->service_id);
                 }
             }
         }
         if (strtolower($inquiry->receiver_country) != 'indonesia') {
             $country = ZoneInternational::model()->findByAttributes(array('country' => strtolower($inquiry->receiver_country)));
             if ($country instanceof ZoneInternational) {
                 $rates = RateInternational::getServices($inquiry->package_weight, $country->zone, $country->transit_time, $customer_id, $use_rate);
                 $product = 'International';
             }
         } else {
             $routing = IntraCityRouting::model()->findByAttributes(array('postcode' => $inquiry->receiver_postal));
             if ($routing instanceof IntraCityRouting) {
                 $rates1 = RateCity::getCityRate(ProductService::ProductCityCourier, $routing->code, $inquiry->package_weight, $customer_id, $use_rate);
                 $rates2 = array();
                 $area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
                 if ($area) {
                     $rates2 = RateDomestic::getServiceList(1, $area['district_id'], $area['zone_id'], $inquiry->package_weight, ProductService::ProductCityCourier, $customer_id, $use_rate);
                     $rates = array_merge($rates1, $rates2);
                 } else {
                     $rates = $rates1;
                 }
                 $product = 'City Courier';
             } else {
                 $area = Area::getZoneID($inquiry->receiver_postal, 'postcode');
                 if ($area) {
                     $rates = RateDomestic::getServiceList(1, $area['district_id'], $area['zone_id'], $inquiry->package_weight, ProductService::ProductDomestic, $customer_id, $use_rate);
                 }
                 $product = 'Domestic';
             }
         }
         $data = new CArrayDataProvider($rates);
         //			CVarDumper::dump($rates,10,true);exit;
         $this->renderPartial('_rates', array('rates' => $data, 'product' => $product, 'customer_id' => $customer_id, 'postal' => $inquiry->receiver_postal, 'country' => $inquiry->receiver_country, 'product' => $product, 'package_weight' => $inquiry->package_weight), false, true);
         Yii::app()->end();
     }
 }