Advertisement
hungaudi

form calculate < jquery php >

Sep 3rd, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 53.74 KB | None | 0 0
  1. <script src="<?php echo base_url(); ?>js/jquery.maskMoney.js" type="text/javascript"></script>
  2. <style type="text/css">
  3. #item_kit_size{
  4.     width:99%; 
  5.     font: 13px solid;
  6.     margin-left: 5px ;
  7.     margin-top: 10px !important;
  8. }
  9. #item_kit_size tr td{
  10.     border: 1px solid #CDCDCD;
  11.     padding: 3px 5px;
  12. }
  13. #item_kit_size tr th{
  14.     border: 1px solid #CDCDCD;
  15.     background: #e8e8e8;
  16.     color: #000;
  17.     padding: 5px 5px;
  18. }
  19. .submit_button{
  20.     margin-bottom:20px
  21. }
  22. #item_kit_feature{
  23.     margin-bottom: 10px;
  24. }
  25. #size_detail tr td, #quantity_detail tr td{
  26.     line-height: 290%;
  27.     border: none;
  28.     border-top: 1px solid #CDCDCD;
  29. }
  30. #size_detail tr:first-child td, #quantity_detail tr:first-child td{
  31.     border-top: none;
  32. }
  33.  
  34. #item_kit_money{
  35.     width:100%;
  36.     font: 13px solid;
  37.     margin-left: 5px ;
  38.     margin-top: 10px !important;
  39. }
  40. #item_kit_money{
  41.     width:99%;
  42. }
  43. #item_kit_money tr td{
  44.     border: 1px solid #CDCDCD;
  45.     padding: 3px 5px;
  46. }
  47. #item_kit_money tr th{
  48.     border: 1px solid #CDCDCD;
  49.     background: #e8e8e8;
  50.     color: #000;
  51.     padding: 5px 5px;
  52. }
  53.  
  54. #table_info_item_kit{
  55.     width: 98%;
  56.     margin-left: 5px;
  57.     font-size: 12px;    
  58. }
  59. #table_info_item_kit tr td{
  60.     padding: 4px 0px;
  61. }
  62. #table_info_item_kit .left_table{
  63.     width: 15%;
  64.     font-weight: bold;
  65. }
  66. #table_info_item_kit .right_table{
  67.     width: 35%;
  68. }    
  69. //Hưng Audi 3-8-15
  70. .item_kit_processes tr td{
  71.     padding: 3px 5px;
  72. }
  73. .time_processes, .processes_money{
  74.     height: 20px;
  75.     text-align: right;
  76.     padding-right: 6px;
  77. }
  78. .id_processes, .unit_time{
  79.     height: 22px;
  80.     padding-left: 5px;
  81.     text-align: left;
  82. }
  83. .cost_money{
  84.     height: 20px;
  85.     text-align: right;
  86.     padding-right: 6px;
  87. }
  88. .cost_name, .outsource_input{
  89.     height: 20px;
  90.     width: 200px;
  91.     text-align: left;
  92.     padding-left: 6px;    
  93. }
  94. #brand_table{
  95.     width: 100%;
  96.     border: 1px solid #CDCDCD;
  97. }    
  98. #brand_table tr, #brand_table tr td, #brand_table tr th{
  99.     border: 1px solid #CDCDCD;
  100.     text-align: center;
  101.     padding: 5px
  102. }
  103. #car_table{
  104.     color: green;
  105. }
  106. .car_th{
  107.     background: #e8e8e8;
  108. }
  109. .brand_tr{
  110.     background: #E1E6FF;
  111. }
  112. .processes_money{
  113.     background: #E1E6FF
  114. }
  115. .space_tr{
  116.     height: 20px;
  117.     background: #d1d1d1
  118. }
  119. .processes_money, .total_money_norms, .processes_money_total, .money_total{
  120.     text-align: right;
  121.     margin-right: 5px;
  122.     border: none
  123. }
  124. .disable_input_cost {
  125.     display: none;
  126. }
  127. .title_cost{
  128.     border: none;
  129.     background: #e8e8e8;
  130.     font-size: 13px;
  131.     font-weight: bold;
  132.     }
  133. tr#car_table_tr_first td, tr#car_table_tr_first, #row_selected tr, #row_selected tr td{
  134.     border: none;
  135. }
  136. .append_car{
  137.     font-size: 16px;
  138.     margin-left: 333px;
  139. }
  140.  
  141. #item_kit_size3{
  142.     width:99%; 
  143.     font: 13px solid;
  144.     margin-left: 5px ;
  145.     margin-top: 10px !important;
  146. }
  147. #item_kit_size3 tr td{
  148.     border: 1px solid #CDCDCD;
  149.     padding: 3px 5px;
  150. }
  151. #item_kit_size3 tr th{
  152.     border: 1px solid #CDCDCD;
  153.     background: #e8e8e8;
  154.     color: #000;
  155.     padding: 5px 5px;
  156. }
  157. .qty_total, .qty_store, .qty_remain, .quantity_size{
  158.     border: none;
  159.     text-align: right;
  160.     font: 13px solid;
  161.     width: 100%
  162. }
  163. .class_hide{
  164.     display: none;
  165. }
  166. </style>
  167. <?php if( $production_design->num_rows() == 0){
  168.     echo 'Chưa có mẫu sản xuất nào được phê duyệt !';exit();
  169. }?>
  170. <ul id="error_message_box"></ul>
  171. <fieldset id="item_kit_info">
  172.     <legend>Thông tin sản phẩm</legend>
  173.     <table id="table_info_item_kit">
  174.         <tr>
  175.             <td class="left_table"><?php echo form_label('Mã sản phẩm:', name, array('class' => wide)); ?></td>
  176.             <td class="right_table"><?=$item_kit_info->item_kit_number;?></td>
  177.             <td class="left_table"><?php echo form_label(lang(item_kits_name) . ':', name, array('class' => wide)); ?></td>
  178.             <td class="right_table"><?=$item_kit_info->name;?></td>
  179.         </tr>
  180.         <tr>
  181.             <td class="left_table"><?php echo form_label(lang(item_kits_unit) . ':', unit, array('class' => wide)); ?></td>
  182.             <td class="right_table"> <?= $this->Unit->get_info($item_kit_info->unit)->name ?></td>
  183.             <td class="left_table"><?php echo form_label(lang(items_category) . ':', category, array('class' => wide)); ?></td>
  184.             <td class="right_table"><?= $this->Category->get_info($item_kit_info->category)->name ?></td>
  185.         </tr>
  186.     </table>    
  187. </fieldset>    
  188. <?php echo form_open_multipart('item_kits/save_item_kit_processes/' . $request_id, array(id => item_kit_form_approve_estimate)); ?>    
  189. <fieldset id="item_kit_feature">
  190.     <legend>Thông tin sản xuất</legend>
  191.     <div class="field_row clearfix">
  192.         <?php echo form_label('Mã yêu cầu:', request_id, array('class' => wide)); ?>
  193.         <div class='form_field'><?= $info_request_production->request_id ?></div>
  194.     </div>
  195.     <h4>&nbsp;* Tổng hợp mẫu sản xuất : </h4>
  196.     <table id=item_kit_size>
  197.         <tr style='text-align: center'>
  198.             <th style="width: 10%" rowspan="2">Tên mẫu</th>
  199.             <th colspan="2">Thông tin size</th>
  200.             <th colspan="9">Công thức nguyên vật liệu</th>
  201.         </tr>
  202.         <tr>
  203.             <th style="width: 5%">Size</th>
  204.             <th style="width: 5%">SL size</th>
  205.             <th style="width: 10%">Mã NVL</th>
  206.             <th style="width: 10%">Tên NVL</th>
  207.             <th style="width: 6%">ĐVT</th>
  208.             <th style="width: 7%">Định mức/SP</th>
  209.             <th style="width: 7%">Tổng định mức</th>
  210.             <th style="width: 10%">Giá nhập</th>
  211.             <th style="width: 10%">Giá xuất</th>
  212.             <th style="width: 10%">SL trong kho</th>
  213.             <th style="width: 10%">SL còn lại</th>
  214.            
  215.         </tr>
  216.         <?php $total_size = 0;
  217.         $total_norms_per_item = 0;
  218.         $total_norms = 0;
  219.         $total_money_norms = 0;
  220.         foreach ($request_feature as $f){
  221.             $i = $this->Item_kit->count_formula_materials($f->feature_id);
  222.             $info_feature = $this->Item_kit->get_info_item_kit_feature($f->feature_id);
  223.             ?>
  224.             <tr>
  225.                 <td style='text-align: left; width: 10%;' rowspan="<?= $i ?>"><?= $info_feature->name_feature ?></td>
  226.                 <?php $info_sizes = $this->Item_kit->get_size_by_request_feature($f->request_id,$f->feature_id);?>
  227.                 <td rowspan="<?= $i ?>" style="width: 5%;">
  228.                     <table id="size_detail">
  229.                         <?php foreach ($info_sizes as $is) {?>
  230.                         <tr>
  231.                             <td>
  232.                                 <?= $is->size?>
  233.                             </td>                            
  234.                         </tr>
  235.                         <?php
  236.                         }?>
  237.                     </table>
  238.                 </td>
  239.                 <td rowspan="<?= $i ?>" style="text-align: right; width: 5%">
  240.                     <table id="quantity_detail">
  241.                         <?php                        
  242.                         foreach ($info_sizes as $is) {
  243.                             $total_size += $is->quantity?>
  244.                             <tr>
  245.                                 <td>
  246.                                     <?= $is->quantity?>
  247.                                 </td>
  248.                             </tr>
  249.                         <?php
  250.                         }?>
  251.                     </table>
  252.                 </td>
  253.                     <?php                
  254.                 $info_formula_material = $this->Item_kit->get_info_formula_materials($f->feature_id);
  255.                 foreach ($info_formula_material as $fm) {
  256.                     $info_store = $this->Create_invetory->check_exist_store_materials();
  257.                     $item_info = $this->Item->get_info_in_store_material($fm[item_id], $info_store[id]);
  258.                     $info_formula_material_item = $this->Item_kit->get_info_formula_materials_item($fm[item_id]);
  259.                     $unit_info = $this->Unit->get_info($info_formula_material_item->unit);
  260.                     $total_size_of_feature_request = 0;
  261.                     foreach ($info_sizes as $val){
  262.                         $total_size_of_feature_request += $val->quantity;
  263.                     }
  264.                     $item_size = $this->Item_kit->get_info_item_size($f->feature_id, $fm[item_id]);
  265.                     $total_quantity = $total_size_of_feature_request * $item_size->quantity;
  266.                     $cost_price = $item_info->quantity_first != 0 ? $item_info->cost_price_rate : $item_info->cost_price;
  267.                    
  268.                     $total_norms_per_item += $item_size->quantity;
  269.                     $total_norms += $total_quantity;
  270.                     $total_money_norms += $total_quantity * $cost_price;
  271.                     ?>
  272.                     <td style="text-align: center; width: 10%;"><?= $item_info->item_number?></td>
  273.                     <td style="width: 10%;"><?= $item_info->name?></td>
  274.                     <td style="width: 6%;"><?= $unit_info->name?></td>
  275.                     <td style="text-align: right; width: 7%;"><?= format_quantity($item_size->quantity)?></td>
  276.                     <td style="text-align: right; width: 7%;"><?= format_quantity($total_quantity)?></td>
  277.                     <td style="text-align: right; width: 10%;">
  278.                         <?= format_quantity($cost_price) ?>
  279.                     </td>
  280.                     <td style="text-align: right; width: 10%;">
  281.                         <?= format_quantity($item_info->quantity_first != 0 ? $item_info->unit_price_rate : $item_info->unit_price) ?>
  282.                     </td>
  283.                     <td style="text-align: right; width: 10%;">
  284.                         <?= format_quantity($item_info->quantity);?>
  285.                     </td>
  286.                     <td style="text-align: right; width: 10%;">
  287.                         <?= format_quantity($item_info->quantity - $total_quantity >= 0 ? $item_info->quantity - $total_quantity : 0)?>
  288.                     </td>
  289.                 </tr>
  290.              <?php  
  291.             }
  292.         }
  293.         ?>
  294.         <tfoot style="font-weight: bold">
  295.             <td colspan="2"> Tổng</td>
  296.             <td style="text-align: right;"><?= $total_size?></td>
  297.             <td colspan="3" style="background: #e8e8e8"></td>
  298.             <td style="text-align: right;"><?= $total_norms_per_item ?></td>
  299.             <td style="text-align: right;"><?= $total_norms ?></td>
  300.             <td colspan="4" style="background: #e8e8e8"></td>
  301.         </tfoot>
  302.     </table>
  303.     <?php
  304.     $quantitys = array();
  305.     foreach ($item_kit_feature->result() as $f){
  306.         $info_formula_material = $this->Item_kit->get_info_formula_materials($f->feature_id);
  307.         $quantitys = array();
  308.         $size_quantity = 0;
  309.         $sizes = $this->Item_kit->get_item_kit_request_feature_by_feature_id($request_id, $f->feature_id);
  310.         foreach ($sizes->result() as $size){
  311.             $size_quantity += $size->quantity;
  312.         }
  313.         $info_formula_material = $this->Item_kit->get_info_formula_materials($f->feature_id);
  314.         if($info_formula_material){
  315.             foreach ($info_formula_material as $fm) {
  316.                 $request_feature_quantity = $fm['quantity'] * $size_quantity;
  317.                 $quantitys[$fm['item_id']] += $request_feature_quantity;
  318.             }
  319.         }
  320.     }?><br>
  321.     <nav>
  322.         <ul class="group">
  323.             <li>
  324.                 <a href="<?php echo base_url(); ?>index.php/item_kits/trading_product" id="trading_item" style="width: 60px !important; ">Nhập hàng</a>
  325.             </li>
  326.         </ul>
  327.     </nav>
  328.     <h4>&nbsp;* Tổng hợp số lượng vật tư : </h4>
  329.  
  330.     <table id=item_kit_size3>
  331.        
  332.         <tr style='text-align: center'>
  333.             <th style="width: 10%">STT</th>
  334.             <th style="width: 20%">Tên vật tư</th>
  335.             <th style="width: 20%">Tổng định mức vật tư</th>
  336.             <th style="width: 20%">Số lượng vật tư trong kho</th>
  337.             <th style="width: 20%">Số lượng vật tư còn lại</th>
  338.             <th style="width: 10%">Nhập kho</th>
  339.         </tr>
  340.         <?php
  341.         $stt = 0;
  342.         foreach ($quantitys as $item_id => $quantity){
  343.             $item_fm = $this->Item_kit->get_item_fm($feature_ids, $item_id);
  344.             $info_store = $this->Create_invetory->check_exist_store_materials();
  345.             $item_info = $this->Item->get_info_in_store_material($item_id, $info_store[id]);
  346.             $stt++;
  347.             ?>
  348.             <tr>
  349.                 <td style="text-align: center"><?= $stt ?></td>
  350.                 <td><?= $this->Item->get_info($item_id)->name ?></td>
  351.                 <td><?php $quantity2 = 0;
  352.                     foreach ($item_fm->result() as $if){
  353.  
  354.                         $info_sizes = $this->Item_kit->get_size_by_request_feature($request_id,$if->feature_id);
  355.                         $total_size_of_feature_request = 0;
  356.                         foreach ($info_sizes as $val){
  357.                             $total_size_of_feature_request += $val->quantity;
  358.                         }
  359.                         $item_size = $this->Item_kit->get_info_item_size($if->feature_id, $item_id);
  360.                         $total_quantity = $total_size_of_feature_request * $item_size->quantity;
  361.                         $quantity2 += $total_quantity;
  362.                         echo form_input(array(
  363.                             'id' => "qty_old$item_id",
  364.                             'class' => "qty_old$if->feature_id$item_id",
  365.                             type => hidden,
  366.                             value => $total_quantity
  367.                         ));
  368.                     }
  369.                     echo form_input(array(
  370.                         'class' => "qty_total qty_total$item_id",
  371.                         id => "qty_total_$item_id",
  372.                         value => $quantity2,
  373.                         readonly => ''
  374.                     ))?>
  375.                 </td>
  376.                 <td><?=
  377.                     form_input(array(
  378.                         'class' => "qty_store qty_store$item_id",
  379.                         value => $item_info->quantity,
  380.                         readonly => ''
  381.                     )) ?>
  382.                 </td>
  383.                 <td><?=
  384.                     form_input(array(
  385.                         'class' => "qty_remain qty_remain$item_id",
  386.                         readonly => '',
  387.                         value => $item_info->quantity - $quantity2
  388.                     )) ?>
  389.                 </td>
  390.                 <td style="text-align: center">
  391.                     <input type='checkbox' id='item_<?= $item_id ?>'
  392.                         value='<?= $item_id ?>'
  393.                         class="import<?= $item_id ?>" />
  394.                 </td>
  395.             </tr>
  396.         <?php
  397.         }?>
  398.     </table><br>
  399.    
  400.     <h4>&nbsp;* Tổng hợp công đoạn SX : </h4>
  401.         <table id="brand_table">
  402.             <tr>
  403.                 <td colspan="6" >
  404.                 <a href="#" class="append" id="append_<?= $item_kit_id?>" style="font-size: 16px; color: blueviolet; "> + Thêm công đoạn </a></td>
  405.             </tr>    
  406.             <tr style="border: 1px solid green">
  407.                 <th style="width: 5%">STT</th>
  408.                 <th style="width: 30%">Công đoạn</th>
  409.                 <th style="width: 10%">Thời gian</th>
  410.                 <th style="width: 20%">Đơn vị thời gian</th>
  411.                 <th style="width: 20%">Chi phí công đoạn</th>
  412.                 <th style="width: 10%">Xóa</th>
  413.             </tr>
  414.             <?php
  415.             $unit_time = array(
  416.                 ''=>'-- Chọn đơn vị thời gian --',
  417.                 0=>Giờ,
  418.                 1=>Ngày
  419.             );
  420.             $processes_money_total = 0;
  421.             if($item_kit_processes->num_rows() == 0){
  422.                 $pro_id = 1;?>
  423.                 <tr class=brand_tr id=brand_tr_<?= $pro_id?> >
  424.                     <td><?=
  425.                         form_input(array(
  426.                             name => "pro_id[$pro_id]",
  427.                             id => "pro_id_$pro_id",
  428.                             'class' => pro_id,
  429.                             type => hidden,
  430.                         ));
  431.                         ?><?= $pro_id?></td>
  432.                     <td><?=
  433.                         form_dropdown("id_processes[$pro_id]", $processes, '', "class=id_processes id=id_processes_$pro_id")
  434.                         ?></td>
  435.                     <td><?=
  436.                         form_input(array(
  437.                             name => "time_processes[$pro_id]",
  438.                             id => "time_processes_$pro_id",
  439.                             'class' => time_processes,
  440.                         ));
  441.                         ?></td>
  442.                     <td><?=
  443.                         form_dropdown("unit_time[$pro_id]", $unit_time, '', "class=unit_time id=unit_time_$pro_id")
  444.                         ?></td>
  445.                     <td><?=
  446.                         form_input(array(
  447.                             name => "processes_money[$pro_id]",
  448.                             id => "processes_money_$pro_id",
  449.                             'class' => processes_money,
  450.                             readonly=>""
  451.                         ));
  452.                         ?></td>
  453.                     <td><a href=# class=del_brand onclick='return deleteBrandRow(this, <?= $pro_id?>);' >X</a></td>
  454.                 </tr>
  455.                 <tr id=car_tr_<?= $pro_id?>>
  456.                     <td colspan="6" style="padding: 0px;">
  457.                         <table class=car_table id=car_table_<?= $pro_id?>>
  458.                             <tr id=car_table_tr_first>
  459.                                 <td colspan="2" >
  460.                                     <a href=# class=append_car id=append_car_<?= $pro_id?> style="color: blue"> + Thêm chi phí</a></td>
  461.                                 <td colspan="2">
  462.                                     <label style="margin-left: 200px">
  463.                                         <input type="checkbox" name="chk[<?= $pro_id?>]" id="chk_<?= $pro_id?>" value="1" > Thuê ngoài
  464.                                     </label>
  465.                                 </td>
  466.                             </tr>    
  467.                             <tr class=car_th>
  468.                                 <th style="width: 30%" class="title_cost<?= $pro_id?>">
  469.                                     Tên chi phí
  470.                                 </th>
  471.                                 <th style="width: 30%" class="title_cost2<?= $pro_id?>">
  472.                                     Tên nhà cung cấp
  473.                                 </th>
  474.  
  475.                                 <th style="width: 30%">Giá chi phí</th>
  476.                                 <th style="width: 30%">Ghi chú</th>
  477.                                 <th style="width: 10%">Xóa</th>
  478.                             </tr>
  479.                             <?php $i=1;
  480.                             $pro_id_i = $pro_id.$i;?>
  481.                             <!-- tr cost name-->
  482.                             <tr class="car_tr car_tr_cost_name<?= $pro_id ?>" >
  483.                                 <td><?= form_input(array(
  484.                                         name => "cost_name[$pro_id_i]",
  485.                                         id => "cost_name_$pro_id_i",
  486.                                         'class' => cost_name,
  487.                                     ));?>
  488.                                 </td>
  489.                                 <td><?= form_input(array(
  490.                                         name => "cost_money[$pro_id_i]",
  491.                                         id => "cost_money_$pro_id_i",
  492.                                         'class' => "cost_money cost_money$pro_id",
  493.                                         onchange => "calculate_cost($pro_id)"
  494.                                     ));?>
  495.                                 </td>
  496.                                 <td><?=
  497.                                     form_textarea(array(
  498.                                         name => "comment[$pro_id_i]",
  499.                                         id => "comment_$pro_id_i",
  500.                                         'class' => "comment comment$pro_id",
  501.                                         'rows' => 3,
  502.                                         'cols' => 20,
  503.                                     ));?>
  504.                                 </td>
  505.                                 <td><a href=# class=del_car onclick='return deleteCarRow(this, <?= $pro_id ?>);' >X</a></td>
  506.                                 </td>
  507.                             </tr>
  508.                            
  509.                             <!--car_tr_chk -->
  510.                             <tr class="car_tr car_tr_chk<?= $pro_id ?>" >
  511.                             </tr>  
  512.                         </table>
  513.                     </td>
  514.                 </tr>
  515.                 <tr><td colspan="6" id="space_tr_<?= $pro_id ?>" class=space_tr></td></tr>
  516.                 <?php
  517.                 echo form_input(array(
  518.                     'class' => count_car,
  519.                     type => hidden,
  520.                     value => $pro_id
  521.                 ));
  522.                 $pro_id++;
  523.             }else{
  524.                 $pro_id = 1;
  525.                 $stt = 1;
  526.                 foreach ($item_kit_processes->result() as $ip){
  527.                     $pro_id = $ip->pro_id;
  528.                     $processes_money_total += $ip->processes_money;
  529.                     $processes_cost = $this->Item_kit->get_info_processes_cost($request_id, $ip->id_processes);
  530.                             ?>
  531.                     <tr class=brand_tr id=brand_tr_<?= $pro_id?>>
  532.                         <td><?=
  533.                             form_input(array(
  534.                                 name => "pro_id[$pro_id]",
  535.                                 id => "pro_id_$pro_id",
  536.                                 'class' => pro_id,
  537.                                 type => hidden,
  538.                             ));
  539.                             ?><?= $stt?></td>
  540.                         <td><?=
  541.                             form_dropdown("id_processes[$pro_id]", $processes, $ip->id_processes, "class=id_processes id=id_processes_$pro_id")
  542.                             ?></td>
  543.                         <td><?=
  544.                             form_input(array(
  545.                                 name => "time_processes[$pro_id]",
  546.                                 id => "time_processes_$pro_id",
  547.                                 'class' => time_processes,
  548.                                 value => $ip->time_processes,
  549.                             ));
  550.                             ?></td>
  551.                         <td><?=
  552.                             form_dropdown("unit_time[$pro_id]", $unit_time, $ip->unit_time, "class=unit_time id=unit_time_$pro_id")
  553.                             ?></td>
  554.                         <td><?=
  555.                             form_input(array(
  556.                                 name => "processes_money[$pro_id]",
  557.                                 id => "processes_money_$pro_id",
  558.                                 'class' => processes_money,
  559.                                 value => number_format($ip->processes_money),
  560.                                 readonly=>""
  561.                             ));
  562.                             ?></td>
  563.                         <td><a href=# class=del_brand onclick='return deleteBrandRow(this, <?= $pro_id?>);' >X</a></td>
  564.                     </tr>
  565.                     <tr id=car_tr_<?= $pro_id?>>
  566.                         <td colspan="6" style="padding: 0px;">
  567.                             <table class=car_table id=car_table_<?= $pro_id?> >
  568.                                 <tr id=car_table_tr_first>
  569.                                     <td colspan="2">
  570.                                         <a href=# class=append_car id=append_car_<?= $pro_id?> style="color: blue"> + Thêm chi phí</a></td>
  571.                                     <td colspan="2">
  572.                                         <label style="margin-left: 200px">
  573.                                             <input type="checkbox" name="chk[<?= $pro_id?>]" id="chk_<?= $pro_id?>" value="1" <?= ($processes_cost->row()->outsource == 0) ? '' : 'checked=checked' ?>> Thuê ngoài
  574.                                         </label>
  575.                                     </td>
  576.                                 </tr>    
  577.                                 <tr class=car_th>
  578.                                     <th style="width: 30%" class="title_cost<?= $pro_id?>">
  579.                                         Tên chi phí
  580.                                     </th>
  581.                                     <th style="width: 30%" class="title_cost2<?= $pro_id?>">
  582.                                         Tên nhà cung cấp
  583.                                     </th>
  584.                                    
  585.                                     <th style="width: 30%">Giá chi phí</th>
  586.                                     <th style="width: 30%">Ghi chú</th>
  587.                                     <th style="width: 10%">Xóa</th>
  588.                                 </tr>
  589.                                 <?php $i=1;
  590.                                 if ( $processes_cost->row()->outsource == 0){
  591.                                     foreach ($processes_cost->result() as $pc){
  592.                                         $pro_id_i = $pro_id.$i;?>
  593.                                         <!-- row cost name -->
  594.                                         <tr class="car_tr car_tr_cost_name<?= $pro_id ?>" >
  595.                                             <td>
  596.                                                 <?php
  597.                                                 echo form_input(array(
  598.                                                     name => "cost_name[$pro_id_i]",
  599.                                                     id => "cost_name_$pro_id_i",
  600.                                                     'class' => cost_name,
  601.                                                     value => $pc->cost_name,
  602.                                                 ));?>
  603.                                             </td>
  604.                                             <td><?=
  605.                                                 form_input(array(
  606.                                                     name => "cost_money[$pro_id_i]",
  607.                                                     id => "cost_money_$pro_id_i",
  608.                                                     'class' => "cost_money cost_money$pro_id",
  609.                                                     value => number_format($pc->cost_money),
  610.                                                     onchange => "calculate_cost($pro_id)"
  611.                                                 ));?>
  612.                                             </td>
  613.                                             <td><?=
  614.                                                 form_textarea(array(
  615.                                                     name => "comment[$pro_id_i]",
  616.                                                     id => "comment_$pro_id_i",
  617.                                                     'class' => "comment comment$pro_id",
  618.                                                     value => $pc->comment,
  619.                                                     rows => 3,
  620.                                                     cols => 20,
  621.                                                 ));?>
  622.                                             </td>
  623.                                             <td><a href=# class=del_car onclick='return deleteCarRow(this, <?= $pro_id ?>);' >X</a></td>
  624.                                         </tr>
  625.                                     <?php $i++;
  626.                                     }//end foreach
  627.                                 }else{?>
  628.                                     <!-- row outsource -->
  629.                                     <tr class="car_tr car_tr_outsource<?= $pro_id ?>" >
  630.                                         <td>
  631.                                             <table id="row_selected" >
  632.                                                 <?php
  633.                                                 $info_supplier = $this->Supplier->get_info($processes_cost->row()->outsource);?>
  634.                                                 <tr>
  635.                                                     <td width="200px">
  636.                                                         <?=
  637.                                                         form_input(array(
  638.                                                             name => "outsource[$pro_id]",
  639.                                                             id => "outsource_$pro_id",
  640.                                                             'class' => outsource,
  641.                                                             value => $processes_cost->row()->outsource,
  642.                                                             type => hidden
  643.                                                         ));?>
  644.                                                         <?= $info_supplier->company_name?></td>
  645.                                                     <td><a href=# style="text-decoration: underline" onclick="return deleteRow(this, <?= $pro_id ?>)">Xóa</a>
  646.                                                     </td>
  647.                                                 </tr>
  648.                                             </table>    
  649.  
  650.                                             <div class="part_outsource<?= $pro_id ?>">
  651.                                                 <?php
  652.                                                 echo form_input(array(
  653.                                                     id => "outsource_input_$pro_id",
  654.                                                     'class' => outsource_input,
  655.                                                     placeholder => "Nhập tên nhà cung cấp"
  656.                                                 )); ?>
  657.                                                 <table id="row_selected<?= $pro_id ?>" >
  658.                                                 </table>
  659.                                             </div>
  660.                                         </td>
  661.                                         <td><?=
  662.                                             form_input(array(
  663.                                                 name => "cost_money[$pro_id]",
  664.                                                 id => "cost_money_$pro_id",
  665.                                                 'class' => "cost_money cost_money$pro_id",
  666.                                                 value => number_format($processes_cost->row()->cost_money),
  667.                                                 onchange => "calculate_cost($pro_id)"
  668.                                             ));?>
  669.                                         </td>
  670.                                         <td><?=
  671.                                             form_textarea(array(
  672.                                                 name => "comment[$pro_id]",
  673.                                                 id => "comment_$pro_id",
  674.                                                 'class' => "comment comment$pro_id",
  675.                                                 value => $processes_cost->row()->comment,
  676.                                                 rows => 3,
  677.                                                 cols => 20,
  678.                                             ));?>
  679.                                         </td>
  680.                                         <td><a href=# class=del_car onclick='return deleteCarRow(this, <?= $pro_id ?>);' >X</a></td>
  681.                                     </tr>
  682.                                 <?php $i++;
  683.                                 }//end else $processes_cost->row()->outsource != 0
  684.                                 echo form_input(array(
  685.                                     id => "count_car_$pro_id",
  686.                                     'class' => count_car,
  687.                                     type => hidden,
  688.                                     value => $i
  689.                                 ));?>
  690.                                    
  691.                                 <!--car_tr_chk -->
  692.                                 <tr class="car_tr car_tr_chk<?= $pro_id ?>" >
  693.                                 </tr>  
  694.                                
  695.                             </table>
  696.                         </td>
  697.                     </tr>
  698.                     <tr><td colspan="6" id="space_tr_<?= $pro_id ?>" class=space_tr></td></tr>
  699.                     <?php
  700.                     $pro_id++;
  701.                     $stt++;
  702.                 }//end foreach processes
  703.             }//end else processes->num_rows
  704.            echo form_input(array(
  705.                 name => count_pro_id,
  706.                 'class' => count_pro_id,
  707.                 type => hidden,
  708.                 value => $pro_id
  709.             ));
  710.             ?>
  711.         </table>
  712.     <h4>&nbsp;* Tổng hợp chi phí SX: </h4>
  713.     <table id=item_kit_money>
  714.         <tr style="text-align: center">
  715.             <th style='width: 33%;'>Tổng chi phí NVL</th>
  716.             <th style='width: 33%;'>Tổng chi phí công đoạn SX</th>
  717.             <th style='width: 33%;'>Tổng tiền</th>
  718.         </tr>
  719.             <tr style='text-align: right'>
  720.                 <td><?= form_input(array(
  721.                     name => total_money_norms,
  722.                     'class' => total_money_norms,
  723.                     value => number_format($total_money_norms),
  724.                     readonly => ''
  725.                 ))?>
  726.                 </td>
  727.                 <td><?= form_input(array(
  728.                     name => processes_money_total,
  729.                     'class' => processes_money_total,
  730.                     readonly => '',
  731.                     value => number_format($processes_money_total)
  732.                 ));?>
  733.                 </td>
  734.                 <td><?= form_input(array(
  735.                     name => money_total,
  736.                     'class' => money_total,
  737.                     readonly => '',
  738.                     value => number_format($total_money_norms + $processes_money_total)
  739.                 ));?>
  740.                 </td>
  741.             </tr>
  742.     </table>
  743.     <br>  
  744.     <?php echo form_submit(array(
  745.         value => lang(common_submit),
  746.         'class' => 'submit_button float_right',
  747.         style => 'margin-bottom:20px',
  748.         name => save_estimate
  749.     ));?>
  750. </fieldset>
  751. <?php echo form_close(); ?>
  752. <script type="text/javascript">
  753. $(document).ready(function(){
  754.     $('#trading_item').click(function(){
  755.         var selected = get_selected_values2();
  756.         if (selected.length == 0)
  757.         {
  758.             alert(<?php echo json_encode(lang('items_must_select_item_for_trading')); ?>);
  759.             return false;
  760.         }
  761.         $(this).attr('href','<?php echo site_url("item_kits/trading_product");?>/'+selected.join('~'));
  762.     });
  763.    
  764.     $('#item_kit_size3').find('.qty_total').each(function (index, element) {
  765.         var item_id = $(element).attr('id').substring($(element).attr('id').lastIndexOf('_') + 1);
  766.         var qty_remain = $('.qty_remain'+item_id).val();
  767.         if(qty_remain < 0){
  768.             $('.import'+item_id).removeClass('class_hide');
  769.         }else{
  770.             $('.import'+item_id).addClass('class_hide');
  771.         }
  772.     });
  773.    
  774.    
  775.     //append cost of processes old
  776.     if($('.count_car').val() == 1){    
  777. //        status_checkbox(1);
  778. //        append_cost_and_click_checkbox(1, 2);
  779.         $("#brand_table").find('.brand_tr').each(function(index, element){
  780.             var pro_id = $(element).attr('id').substring($(element).attr('id').lastIndexOf('_') + 1);
  781.             var i = $('#count_car_'+pro_id).val();
  782.            
  783.             status_checkbox(pro_id);
  784.             append_cost_and_click_checkbox(pro_id, i);
  785.         });
  786.     }else{
  787.         $("#brand_table").find('.brand_tr').each(function(index, element){
  788.             var pro_id = $(element).attr('id').substring($(element).attr('id').lastIndexOf('_') + 1);
  789.             var i = $('#count_car_'+pro_id).val();
  790.            
  791.             status_checkbox(pro_id);
  792.             append_cost_and_click_checkbox(pro_id, i);
  793.         });
  794.     }
  795.     //append processes & cost new
  796.     var pro_id = $('.count_pro_id').val();
  797.     var ii = 1;  
  798.     var stt = $('#brand_table .brand_tr').length + 1;
  799.     $('.append').click(function(){
  800.         $('#brand_table').append(
  801.             '<tr class=brand_tr id=brand_tr_'+pro_id+'>'
  802.                 +'<td><input type=hidden name=pro_id['+pro_id+'] id="pro_id_'+pro_id+'" class=pro_id value='+pro_id+'  >'+stt+'</td>'
  803.                 +'<td>'
  804.                     +'<select name=id_processes['+pro_id+'] class=id_processes id=id_processes_'+pro_id+' >'
  805.                         +'<option value= >-- Chọn công đoạn --</option>'
  806.                         +'<?php foreach($this->Item_kit->get_all_processes_new()->result_array() as $r){ ?>'
  807.                             +'<option value=<?= $r['id_processes']?> > <?= $r['name_processes']?></option>'
  808.                         +'<?php }?>'
  809.                     +'</select>'
  810.                 +'</td>'
  811.                 +'<td><input name=time_processes['+pro_id+'] id=time_processes_'+pro_id+' class=time_processes ></td>'
  812.                 +'<td>'
  813.                     +'<select name=unit_time['+pro_id+'] id=unit_time_'+pro_id+' class=unit_time >'
  814.                         +'<option value= >-- Chọn đơn vị thời gian --</option>'
  815.                         +'<option value=0 >Giờ</option>'
  816.                         +'<option value=1 >Ngày</option>'
  817.                     +'</select>'
  818.                 +'</td>'
  819.                 +'<td><input name=processes_money['+pro_id+'] id=processes_money_'+pro_id+' \n\
  820.                         class=processes_money readonly ></td>'
  821.                 +'<td><a href=# class=del_brand onclick="return deleteBrandRow(this, '+pro_id+');" >X</a></td>'
  822.             +'</tr>'
  823.             +'<tr id=car_tr_'+pro_id+'>'        
  824.                 +'<td colspan="6" style="padding: 0px;">'
  825.                     +'<table class=car_table id=car_table_'+pro_id+'>'
  826.                         +'<tr id=car_table_tr_first>'
  827.                             +'<td colspan="2" >'
  828.                                 +'<a href=# class=append_car id=append_car_'+pro_id+' style=" color: blue"> + Thêm chi phí</a></td>'
  829.                             +'<td colspan=2 >'
  830.                                 +'<label style="margin-left: 200px">'
  831.                                     +'<input type=checkbox name=chk id=chk_'+pro_id+' value=1 > Thuê ngoài'
  832.                                 +'</label>'
  833.                             +'</td>'
  834.                         +'</tr>'  
  835.                         +'<tr class=car_th>'
  836.                             +'<th style="width: 30%" class=title_cost'+pro_id+'>Tên chi phí</th>'
  837.                             +'<th style="width: 30%; display:none" class=title_cost2'+pro_id+'>Tên nhà cung cấp</th>'
  838.                             +'<th style="width: 30%">Giá chi phí</th>'
  839.                             +'<th style="width: 30%">Ghi chú</th>'
  840.                             +'<th style="width: 10%">Xóa</th>'
  841.                         +'</tr>'
  842.                         +'<tr class="car_tr car_tr_cost_name'+pro_id+'">'
  843.                             +'<td>'
  844.                                 +'<input name=cost_name['+pro_id+ii+'] id=cost_name_'+pro_id+ii+' class=cost_name >'
  845.                             +'</td>'
  846.                             +'<td>'
  847.                                 +'<input name=cost_money['+pro_id+ii+'] id=cost_money_'+pro_id+ii+' \n\
  848.                                     class="cost_money cost_money'+pro_id+'" onchange="calculate_cost('+pro_id+')" >'
  849.                             +'</td>'
  850.                             +'<td><textarea name=comment['+pro_id+ii+'] id=comment_'+pro_id+ii+' \n\
  851.                         class="comment comment'+pro_id+'" type=textarea cols=20 rows=3 ></textarea></td>'
  852.                             +'<td><a href=# class=del_car onclick="return deleteCarRow(this, '+pro_id+')" >X</a></td>'
  853.                         +'</tr>'
  854.                         +'<tr class=car_tr_chk'+pro_id+' >'
  855.                         +'</tr>'
  856.                     +'</table>'
  857.                 +'</td>'
  858.             +'</tr>'
  859.             +'<tr><td colspan="6" id=space_tr_'+pro_id+' class=space_tr></td></tr>'
  860.         );
  861.         //only enter number
  862.         $(".time_processes").keydown(function (e) {
  863.             if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
  864.               (e.keyCode == 65 && (e.ctrlKey === true || e.metaKey === true)) ||
  865.               (e.keyCode >= 35 && e.keyCode <= 40)) {
  866.                 return;
  867.             }
  868.             if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  869.                 e.preventDefault();
  870.             }
  871.         });
  872.         $(".cost_money").keydown(function (e) {
  873.             if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
  874.               (e.keyCode == 65 && (e.ctrlKey === true || e.metaKey === true)) ||
  875.               (e.keyCode >= 35 && e.keyCode <= 40)) {
  876.                 return;
  877.             }
  878.             if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  879.                 e.preventDefault();
  880.             }
  881.         });    
  882.         append_cost_and_click_checkbox(pro_id, 2);
  883.         pro_id++;
  884.         stt++;
  885.         return false;
  886.     });
  887.     setTimeout(function () {
  888.         $(":input:visible:first", "#item_kit_form_approve_estimate").focus();
  889.     }, 100);
  890.     var submitting = false;
  891.     $('#item_kit_form_approve_estimate').validate({  
  892.         submitHandler: function (form) {
  893.             if (submitting)
  894.                 return;
  895.             submitting = true;
  896.             $(form).mask(<?php echo json_encode(lang('common_wait')); ?>);
  897.             $(form).ajaxSubmit({
  898.                 success: function (response) {
  899.                     submitting = false;
  900.                     tb_remove();
  901.                     post_item_kit_form_submit(response);
  902.                 },
  903.                 dataType: 'json'
  904.             });
  905.         },
  906.         errorLabelContainer: "#error_message_box",
  907.         wrapper: "li",        
  908.     });
  909. });
  910. function status_checkbox(pro_id){
  911.     if ($('#chk_'+pro_id).is(':checked')){
  912.         //title
  913.         $('#car_table_'+pro_id+' .car_th .title_cost'+pro_id).hide();
  914.         $('#car_table_'+pro_id+' .car_th .title_cost2'+pro_id).show();
  915.         //link append
  916.         $('#append_car_'+pro_id).hide();
  917.         //hide div
  918.         $('.part_outsource'+pro_id).hide();
  919.         //hide show tr
  920.         $('.car_tr_cost_name'+pro_id).hide();
  921.         $('.car_tr_outsource'+pro_id).show();
  922.         auto_complete(pro_id);
  923.     } else{
  924.         //title
  925.         $('#car_table_'+pro_id+' .car_th .title_cost'+pro_id).show();
  926.         $('#car_table_'+pro_id+' .car_th .title_cost2'+pro_id).hide();
  927.         //link append
  928.         $('#append_car_'+pro_id).show();
  929.         //hide show tr
  930.         $('.car_tr_cost_name'+pro_id).show();
  931.         $('.car_tr_outsource'+pro_id).hide();
  932.     }    
  933. }
  934. function append_cost_and_click_checkbox(pro_id, i){
  935.     append_cost(pro_id, i);
  936.    
  937.     $('#chk_'+pro_id).click(function(){
  938.         if ($('#chk_'+pro_id).is(':checked')){
  939.             //title
  940.             $('#car_table_'+pro_id+' .car_th .title_cost'+pro_id).hide();
  941.             $('#car_table_'+pro_id+' .car_th .title_cost2'+pro_id).show();
  942.             //link append
  943.             $('#append_car_'+pro_id).hide();
  944.             //remove tr chk
  945.             $('.car_tr_cost_name'+pro_id+' td').remove();
  946.             $('.car_tr_chk'+pro_id+' td').remove();
  947.            
  948.             append_outsource_chk(pro_id);
  949.             auto_complete(pro_id);
  950.         } else{
  951.             //title
  952.             $('#car_table_'+pro_id+' .car_th .title_cost'+pro_id).show();
  953.             $('#car_table_'+pro_id+' .car_th .title_cost2'+pro_id).hide();
  954.             //link append
  955.             $('#append_car_'+pro_id).show();
  956.             //remove tr chk  
  957.             $('.car_tr_outsource'+pro_id).remove();
  958.             $('.car_tr_chk'+pro_id+' td').remove();
  959.            
  960.             append_cost_name_chk(pro_id);
  961.         }
  962.         calculate_cost(pro_id);
  963.     });
  964. }    
  965. function append_cost(pro_id, i){
  966.     $('#append_car_'+pro_id).click(function(){
  967.         $('#car_table_'+pro_id).append(
  968.             '<tr class="car_tr car_tr_cost_name'+pro_id+'" >'
  969.                 +'<td><input name=cost_name['+pro_id+i+'] id=cost_name_'+pro_id+i+' class="cost_name cost_name'+pro_id+'" ></td>'
  970.                 +'<td><input name=cost_money['+pro_id+i+'] id=cost_money_'+pro_id+i+' \n\
  971.                     class="cost_money cost_money'+pro_id+'" onchange="calculate_cost('+pro_id+')" ></td>'
  972.                 +'<td><textarea name=comment['+pro_id+i+'] id=comment_'+pro_id+i+' \n\
  973.                 class="comment comment'+pro_id+'" type=textarea cols=20 rows=3 ></textarea></td>'
  974.                 +'<td><a href=# class=del_brand onclick="return deleteCarRow(this, '+pro_id+');" >X</a></td>'
  975.             +'</tr>'
  976.         );
  977.         $(".cost_money").keydown(function (e) {
  978.             if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
  979.               (e.keyCode == 65 && (e.ctrlKey === true || e.metaKey === true)) ||
  980.               (e.keyCode >= 35 && e.keyCode <= 40)) {
  981.                 return;
  982.             }
  983.             if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  984.                 e.preventDefault();
  985.             }
  986.         });
  987.         i++;
  988.         //$('.cost_money'+pro_id).maskMoney();
  989.         return false;
  990.     });
  991. }
  992. function append_cost_name_chk(pro_id){
  993.     $('.car_tr_chk'+pro_id).append(
  994.         '<td>'
  995.             +'<input id=cost_name_'+pro_id+' class="cost_name cost_name'+pro_id+'" name=cost_name['+pro_id+'] >'
  996.         +'</td>'
  997.         +'<td>'
  998.             +'<input name=cost_money['+pro_id+'] id=cost_money_'+pro_id+' class="cost_money cost_money'+pro_id+'" onchange="calculate_cost('+pro_id+')" >'
  999.         +'</td>'
  1000.         +'<td>'
  1001.             +'<textarea name=comment['+pro_id+'] id=comment_'+pro_id+' class="comment comment'+pro_id+'" rows=3 cols=20 ></textarea>'
  1002.         +'</td>'
  1003.         +'<td><a href=# class=del_car onclick="return deleteCarRow(this, '+pro_id+')" >X</a></td>'
  1004.     );
  1005.     $(".cost_money").keydown(function (e) {
  1006.         if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
  1007.           (e.keyCode == 65 && (e.ctrlKey === true || e.metaKey === true)) ||
  1008.           (e.keyCode >= 35 && e.keyCode <= 40)) {
  1009.             return;
  1010.         }
  1011.         if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  1012.             e.preventDefault();
  1013.         }
  1014.     });
  1015. }
  1016. function append_outsource_chk(pro_id){
  1017.     $('.car_tr_chk'+pro_id).append(
  1018.         '<td>'
  1019.             +'<div class=part_outsource'+pro_id+'>'
  1020.                 +'<input id=outsource_input_'+pro_id+' class=outsource_input placeholder = "Nhập tên nhà cung cấp" >'
  1021.                 +'<table id=row_selected'+pro_id+' >'
  1022.                 +'</table>'
  1023.             +'</div>'
  1024.         +'</td>'
  1025.         +'<td>'
  1026.             +'<input name=cost_money['+pro_id+'] id=cost_money_'+pro_id+' class="cost_money cost_money'+pro_id+'" onchange="calculate_cost('+pro_id+')" >'
  1027.         +'</td>'
  1028.         +'<td>'
  1029.             +'<textarea name=comment['+pro_id+'] id=comment_'+pro_id+' class="comment comment'+pro_id+'" rows=3 cols=20 ></textarea>'
  1030.         +'</td>'
  1031.         +'<td><a href=# class=del_car onclick="return deleteCarRow(this, '+pro_id+')" >X</a></td>'
  1032.     );
  1033.     $(".cost_money").keydown(function (e) {
  1034.         if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
  1035.           (e.keyCode == 65 && (e.ctrlKey === true || e.metaKey === true)) ||
  1036.           (e.keyCode >= 35 && e.keyCode <= 40)) {
  1037.             return;
  1038.         }
  1039.         if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  1040.             e.preventDefault();
  1041.         }
  1042.     });
  1043. }
  1044. function auto_complete(pro_id){
  1045.     $("#outsource_input_"+pro_id).autocomplete({
  1046.         source: '<?php echo site_url("sales/supplier_search_cost"); ?>',
  1047.         delay: 10,
  1048.         autoFocus: false,
  1049.         minLength: 0,
  1050.         select: function (event, ui){
  1051.             $("#outsource_input_"+pro_id).val("");
  1052.             if ($("#row_selected" + ui.item.value).length == 1){
  1053.                 $("#row_selected" + ui.item.value).val(parseFloat($("#row_selected" + ui.item.value).val()) + 1);
  1054.             }else{
  1055.                 $('#outsource_input_'+pro_id).hide();
  1056.                 $("#row_selected"+pro_id).append(
  1057.                     '<tr style="border: none">'
  1058.                     +'<td width="80%" style="border: none"><input type=hidden id=outsource_'+pro_id+' name=outsource['+pro_id+'] value=' + ui.item.value + ' />' + ui.item.label + '</td>'
  1059.                     +'<td style="border: none"><a href=# style="text-decoration: underline" onclick="return deleteRow(this, '+pro_id+')">Xóa</a></td>'
  1060.                     +'</tr>'
  1061.                 );
  1062.             }
  1063.             return false;
  1064.         }
  1065.     });
  1066. }
  1067. function deleteRow(link, pro_id){
  1068.     $('#outsource_input_'+pro_id).show();
  1069.     $('.part_outsource'+pro_id).show();
  1070.     $(link).parent().parent().remove();
  1071.     return false;
  1072. }
  1073. function deleteBrandRow(link, pro_id){
  1074.     var count_tr_brand = $('#brand_table .brand_tr').length;
  1075.     if(count_tr_brand == 1){
  1076.         alert('Bạn không thể xóa hết công đoạn !');
  1077.         return false;
  1078.     }
  1079.     $(link).parent().parent().remove();
  1080.     $('#car_tr_'+pro_id).remove();
  1081.     $('#space_tr_'+pro_id).remove();
  1082.     calculate_cost(pro_id);
  1083.     return false;
  1084. }
  1085. function deleteCarRow(link, pro_id){
  1086. //    var count_tr_car = $('#car_table_'+pro_id+' .car_tr').length;
  1087. //    if(count_tr_car == 1){
  1088. //        alert('Bạn không thể xóa hết chi phí của 1 công đoạn !');
  1089. //        return false;
  1090. //    }    
  1091.     $(link).parent().parent().remove();
  1092.     calculate_cost(pro_id);
  1093.     return false;
  1094. }
  1095. function calculate_cost(pro_id) {
  1096.     var sum_cost=0;
  1097.     $('.cost_money'+pro_id).each(function () {
  1098.         var a = $(this).val().replace(/,/g, "");
  1099.         sum_cost += +a;
  1100.     });
  1101.     $('#processes_money_'+pro_id).val((sum_cost+'').replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));//add ',' to show
  1102.    
  1103.     var sum_processes=0;
  1104.     $('.processes_money').each(function () {
  1105.         var a = $(this).val().replace(/,/g, "");
  1106.         sum_processes += +a;
  1107.     });
  1108.     $('.processes_money_total').val((sum_processes+'').replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));//add ',' to show
  1109.    
  1110.     var money_total = +$('.total_money_norms').val().replace(/,/g, "") + sum_processes;
  1111.     $('.money_total').val((money_total+'').replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));//add ',' to show    
  1112. }    
  1113. $('.submit_button').click(function () {
  1114.     var arr_id_processes = [];
  1115.     var arr_id_processes_none = [];
  1116.     var arr_time_processes = [];
  1117.     var arr_unit_time = [];
  1118.     var arr_cost_name = [];
  1119.     var arr_cost_money = [];
  1120.    
  1121.     $(".brand_tr").find('.pro_id').each(function (index, element) {
  1122.         var pro_id = $(element).attr('id').substring($(element).attr('id').lastIndexOf('_') + 1);
  1123.        
  1124.         if($('#id_processes_' + pro_id).val()){
  1125.             arr_id_processes.push(pro_id);
  1126.            
  1127.             if ( ! $('#time_processes_' + pro_id).val()
  1128.                 || $('#time_processes_' + pro_id).val() == 0) {
  1129.                 arr_time_processes.push(pro_id);
  1130.             }
  1131.             if ( ! $('#unit_time_' + pro_id).val()) {
  1132.                 arr_unit_time.push(pro_id);
  1133.             }
  1134.         }else{
  1135.             if( ! $('#id_processes_' + pro_id).val()){
  1136.                 arr_id_processes_none.push(pro_id);
  1137.             }
  1138.         }
  1139.         $(".car_tr").find('.cost_name').each(function (index, element) {
  1140.             var pro_id_i = $(element).attr('id').substring($(element).attr('id').lastIndexOf('_') + 1);  
  1141.            
  1142.             if ( ! $('#cost_name_' + pro_id_i).val()) {
  1143.                 arr_cost_name.push(pro_id_i);
  1144.             }
  1145.             if ( ! $('#cost_money_' + pro_id_i).val()
  1146.                 || $('#cost_money_' + pro_id_i).val() == 0) {
  1147.                 arr_cost_money.push(pro_id_i);
  1148.             }            
  1149.         });
  1150.     });
  1151.     if (arr_id_processes.length < 1) {
  1152.         alert("Bạn chưa chọn công đoạn nào !");
  1153.         return false;
  1154.     }
  1155.     if (arr_id_processes_none.length > 0) {
  1156.         alert("Có công đoạn chưa thấy chọn !");
  1157.         return false;
  1158.     }
  1159.     if (arr_time_processes.length > 0) {
  1160.         alert("Công đoạn đã chọn chưa có thời gian !");
  1161.         return false;
  1162.     }
  1163.     if (arr_unit_time.length > 0) {
  1164.         alert("Công đoạn đã chọn chưa có đơn vị thời gian !");
  1165.         return false;
  1166.     }
  1167.     if (arr_cost_name.length > 0) {
  1168.         alert("Bạn chưa điền tên chi phí !");
  1169.         return false;
  1170.     }
  1171.     if (arr_cost_money.length > 0) {
  1172.         alert("Bạn chưa điền giá chi phí !");
  1173.         return false;
  1174.     }
  1175. });
  1176. //$('.cost_money').maskMoney();//ko onchange dc..........
  1177. $('.processes_money').maskMoney();
  1178. //only enter number
  1179. $(".time_processes").keydown(function (e) {
  1180.     if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
  1181.       (e.keyCode == 65 && (e.ctrlKey === true || e.metaKey === true)) ||
  1182.       (e.keyCode >= 35 && e.keyCode <= 40)) {
  1183.         return;
  1184.     }
  1185.     if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  1186.         e.preventDefault();
  1187.     }
  1188. });    
  1189. $(".cost_money").keydown(function (e) {
  1190.     if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 110, 190]) !== -1 ||
  1191.       (e.keyCode == 65 && (e.ctrlKey === true || e.metaKey === true)) ||
  1192.       (e.keyCode >= 35 && e.keyCode <= 40)) {
  1193.         return;
  1194.     }
  1195.     if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
  1196.         e.preventDefault();
  1197.     }
  1198. });
  1199. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement