column('name','value'); foreach($quotation_detail as &$v){ $amount_including_tax += $v['num'] * $v['tax_inclusive_price']; $v['tax_inclusive_amount'] = $v['num'] * $v['tax_inclusive_price']; $v['tax_exclusive_amount'] = $v['num'] * $v['tax_inclusive_price'] * (1- $tax_rate_dict[$v['tax_rate']] / 100); } Db::startTrans(); try { $quotation = Quotation::create([ 'org_id' => $params['org_id'], 'dept_id' => $params['dept_id'], 'custom_id' => $params['custom_id'], 'code' => data_unique_code('报价单'), 'quotation_date' => !empty($params['quotation_date']) ? strtotime($params['quotation_date']) : 0, 'create_user' => $params['create_user'] ?? '', 'invoice_type' => $params['invoice_type'] ?? 0, 'amount_including_tax' => $amount_including_tax, 'freight' => $params['freight'], 'other_fee' => $params['other_fee'], 'total_amount' => $amount_including_tax + $params['freight'] + $params['other_fee'], 'customer_require' => $params['customer_require'] ?? '', 'remark' => $params['remark'] ?? '', 'annex' => !empty($params['annex']) ? $params['annex'] : null, ]); foreach ($quotation_detail as $item) { QuotationDetail::create([ 'quotation_id' => $quotation->id, 'product_id' => $item['product_id'], 'num' => $item['num'], 'tax_rate' => $item['tax_rate'], 'tax_inclusive_price' => $item['tax_inclusive_price'], 'tax_inclusive_amount' => $item['tax_inclusive_amount'], 'tax_exclusive_amount' => $item['tax_exclusive_amount'], 'remark' => $item['remark'] ?? '' ]); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 获取报价单详情 * @param $params * @return array * @author likeadmin * @date 2023/11/27 17:23 */ public static function detail($params): array { $data = Quotation::field('id,org_id,dept_id,custom_id,quotation_date,create_user,invoice_type,amount_including_tax,freight,other_fee,total_amount,customer_require,remark,annex')->findOrEmpty($params['id']); $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); $custom = Custom::field('name,master_name,master_phone')->where('id',$data['custom_id'])->findOrEmpty(); $data['org_name'] = $org['name']; $data['dept_name'] = $dept['name']; $data['custom_name'] = $custom['name']; $data['custom_master_name'] = $custom['master_name']; $data['custom_master_phone'] = $custom['master_phone']; $data['invoice_type_text'] = $data->invoice_type_text; return $data->toArray(); } }