Example #1
0
 /**
  * 生产单号
  */
 public static function generateOrderNo()
 {
     $last_order = SampleProduceOrder::find('create_time >= ?', strtotime(date('Y-m-01 00:00:00')))->order('create_time DESC')->one();
     $no = '00';
     if ($last_order) {
         $last_no = substr($last_order->order_no, -2);
         if ($last_no == 99) {
             throw new Exception('order no full');
         }
         $new_no = (int) $last_no + 1;
         $no = str_pad($new_no, 2, '0', STR_PAD_LEFT);
     }
     $no = 'S' . date('ym') . $no;
     return $no;
 }
 /**
  * 更新生产单的状态
  * @param $produce_order_id
  */
 private function updateProduceOrderState($produce_order_id)
 {
     $order = SampleProduceOrder::findOneByPk($produce_order_id);
     //处理生产单状态
     $has_no_finish_count = SampleProduceOrderMapSamples::find('produce_order_id=? AND state <> ?', $produce_order_id, SampleProduceOrderMapSamples::STATE_FINISH)->count();
     //所有子项都完成了,改为完成
     if (!$has_no_finish_count) {
         $ctrl = new SampleProduceOrderController();
         $ctrl->state(array('id' => $produce_order_id, 'state' => SampleProduceOrder::STATE_FINISH));
     } else {
         if ($order->state == SampleProduceOrder::STATE_FINISH) {
             $order->state = SampleProduceOrder::STATE_PRODUCING;
             $order->save();
         }
     }
 }
Example #3
0
 public function __construct($data = array())
 {
     parent::__construct($data);
     $this->setPropertiesDefine(array('customer_id' => array('display' => function (BusinessOrder $item) {
         return Customer::findOneByPk($item->customer_id)->company_alias_name;
     }, 'alias' => '公司简称'), 'customer_contact_id' => array('display' => function (BusinessOrder $item) {
         return CustomerContact::findOneByPk($item->customer_contact_id)->chinese_name;
     }, 'alias' => '联系人'), 'pay_type_id' => array('options' => function () {
         $tmp = PayType::find('state=?', PayType::STATE_ENABLED)->all(true);
         return array_combine(array_column($tmp, 'id'), array_column($tmp, 'name'));
     }, 'display' => function (self $item) {
         $tmp = PayType::findOneByPk($item->pay_type_id);
         if (!$tmp) {
             return '';
         }
         return $tmp->state == PayType::STATE_ENABLED ? $tmp->name : '<del>' . $tmp->name . '</del>';
     }), 'settle_currency_name' => array('getter' => function (BusinessOrder $item) {
         return $item->getPropertiesDefine('settle_currency')['options'][$item->settle_currency];
     }), 'sample_produce_order' => array('getter' => function (self $item) {
         return SampleProduceOrder::find('business_order_id=?', $item->id)->one();
     })));
 }
 public function update($get, $post)
 {
     $order = SampleProduceOrder::findOneByPk($get['id']) ?: new SampleProduceOrder();
     if ($post) {
         if ($post['produce_type'] == SampleProduceOrder::TYPE_ORDER) {
             if ($post['business_order_no']) {
                 $post['business_order_id'] = BusinessOrder::find('order_no=?', $post['business_order_no'])->ceil('id');
             }
             if (!$post['business_order_id']) {
                 return new Result('您输入的订单号没有对应的订单:' . $post['business_order_no']);
             }
         }
         $org_id = $order->boss_head_employee_id;
         $order->setValues($post);
         if (!$order->id) {
             $order->boss_head_employee_id = Auth::instance()->getLoginUserId();
         } else {
             $order->boss_head_employee_id = $org_id;
         }
         $result = parent::update($get, $post);
         if ($result->isSuccess()) {
             return new Result('操作成功', true);
         }
     }
     $customer_list = Customer::find()->all();
     $current_contact_list = array();
     if ($order->id) {
         $current_contact_list = CustomerContact::find('customer_id =?', $order->contact->customer_id)->all();
     }
     $all_contact_list = CustomerContact::find()->all(true);
     $all_contact_list = array_group($all_contact_list, 'customer_id');
     return array('order' => $order, 'customer_list' => $customer_list, 'all_contact_list' => $all_contact_list, 'current_contact_list' => $current_contact_list);
 }
Example #5
0
	<form action="<?php 
echo $this->getUrl('SampleProduceOrder/update', array('id' => $order->id));
?>
" class="frm" rel="async" method="post">

		<table class="frm-tbl">
			<caption><?php 
echo $order->id ? '更新' : '新增';
?>
样品生产单</caption>
			<tbody>
				<tr>
					<td class="col-label">生产单号</td>
					<td>
						<input type="text" name="order_no" class="txt" value="<?php 
echo $order->order_no ?: SampleProduceOrder::generateOrderNo();
?>
" readonly="readonly">
					</td>
				</tr>
				<tr>
					<td class="col-label">客户</td>
					<td>
						<select name="customer_id" required="required">
							<option value="">请选择客户</option>
							<?php 
foreach ($customer_list as $cus) {
    ?>
								<option value="<?php 
    echo $cus->id;
    ?>
 /**
  * @param $get
  * @param $post
  * @return array
  * @throws Exception
  */
 public function addSampleProduceOrder($get, $post)
 {
     $business_order_id = $get['id'];
     $business_order = BusinessOrder::findOneByPk($business_order_id);
     $sample_produce_order = new SampleProduceOrder();
     if ($post) {
         $sample_list = BusinessOrderSamples::find('business_order_id=?', $business_order_id)->all();
         if (empty($sample_list)) {
             throw new BizException('样品列表为空,您必须先添加样品');
         }
         $exception = Model::transaction(function () use($sample_produce_order, $post, $sample_list, $business_order) {
             $sample_produce_order->setValues($post);
             $sample_produce_order->save();
             $data = array();
             /** @var BusinessOrderSamples $sm */
             foreach ($sample_list as $sm) {
                 $data[] = array('produce_order_id' => $sample_produce_order->id, 'sample_id' => $sm->sample_id, 'produce_num' => BusinessOrder::DEFAULT_PRODUCE_NUM, 'produce_request' => '无', 'produce_process_state' => 0, 'produce_employee_id' => 0);
             }
             SampleProduceOrderMapSamples::insertMany($data, false);
         });
         if ($exception) {
             dump($exception, 1);
             throw new BizException($exception);
         }
         return new Result('送样成功', true);
     }
     $sample_produce_order = new SampleProduceOrder();
     $customer = Customer::find('id = ?', $business_order->customer_id)->one();
     $current_contact = CustomerContact::find('id =?', $business_order->customer_contact_id)->one();
     return array('sample_produce_order' => $sample_produce_order, 'business_order' => $business_order, 'customer' => $customer, 'current_contact' => $current_contact);
 }