<%@ Page Title="" Language="C#" MasterPageFile="~/bps/bps.Master" AutoEventWireup="true" ClientIDMode="Static" CodeBehind="quote_edit.aspx.cs" Inherits="bps.bps.quote_edit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">






     <h1  class="border-active subnav" ><%=isen?"Edit Quote Form":"修改报价单" %>   </h1>

    <div class=right-action>
        <a href="quote_list.aspx" class="btn btn-primary btn-sm" ><%=isen?"Back":"返回" %>  </a>  
         
    </div>


    <style>
        table.add th {
         font-weight:normal;
        }
    </style>

    <div>
     
       <div class="content">
 
            

 <div  >

     

             <asp:Panel runat="server" ID="pnl_rotate">


                 
                    <table class="table table-condensed add"   >
                     
                          <tr>
                                <th  width="100px" ><%=isen?"Price Code":"报价单号" %> <font color=red>*</font></th>
                                <td width="200px">
                                   
                                    <asp:TextBox class="form-control"    ID="quotecode"  Enabled="false"  runat="server"></asp:TextBox>
                                   
                                </td>
                            
                    
                               <th width="100px"> <%=isen?"Product Code":"成品编号" %>  </th>
                            <td width="200">
                            <asp:TextBox id="productcode" Runat="Server"  ReadOnly="true"  class="form-control"  ></asp:TextBox>
                            </td>

                              
                              <th width="100">成品名称</th>
                            <td width="200">
                                    <asp:TextBox id="productname" Runat="Server"  ReadOnly="true"  class="form-control"  ></asp:TextBox>

                            </td>

                            </tr>

                   
                        <tr>
                             
                              <th  >
                                 <%=isen?"Customer Code":"客户号" %>    
                              </th>
                              <td >

                                      <asp:TextBox id="customercode" Runat="Server"     ReadOnly="true"   class="form-control"  ValidationGroup="Add"></asp:TextBox>
 
                              </td>

                              <th>
                                 <%=isen?"Customer Name":"客户名称" %>    
                              </th>
                              <td  >

                                      <asp:TextBox id="customername" Runat="Server"     ReadOnly="true"   class="form-control"  ValidationGroup="Add"></asp:TextBox>
 
                              </td>



                            
                            

                           <th  >  报价单版本号  </th>
                            <td >
                            <asp:TextBox id="revision" Runat="Server"  ReadOnly="true"  class="form-control"   ></asp:TextBox>
                            </td>

                              


                        </tr>

                     


                        <tr>
                            <th>销售人员</th>
                            <td>
                                  <asp:TextBox id="sellname" Runat="Server"      class="form-control"  ></asp:TextBox>
                            </td>


                            <th>报价日期</th>

                            <td>
                                <asp:TextBox id="dt_quotedate" Runat="Server"     class="form-control _dt"  ></asp:TextBox>
                            </td>

                            <th></th>

                            <td></td>
                        </tr>

                          
                          <tr>

                             <th  > <%=isen?"Quantity":"订购量" %> <font color=red>*</font> </th>
                            <td >
                            <asp:TextBox id="quantity" Runat="Server"   class="form-control" ></asp:TextBox>

                             </td>

                                
                              <th  >
                                 <%=isen?"UOM":"单位" %>    
                              </th>
                              <td  >

                                   <asp:DropDownList runat="server"  CssClass="form-control"  ID="ddl_piece"></asp:DropDownList>
 
                              </td>

                              <th></th>
                              <td>
                                   

                              </td>
                            </tr>








                        <tr>
         <td style="background-color:#f5f5f5" colspan="6">
             
         </td>
     </tr>
</table>







  <table class="table table-condensed add"   >
                     
                          <tr>
                                <th  width="100px" >磨具费用</th>
                                <td width="200px">
                                   
                                   <asp:TextBox id="toolingcost" Runat="Server"   class="form-control" ></asp:TextBox>
                                   
                                </td>
                            
                    
                               <th width="100px">    </th>
                            <td width="200">
                          
                            </td>

                              
                              <th width="100"> </th>
                            <td width="200">
                                   

                            </td>

                            </tr>



      <tr>
         <td style="background-color:#f5f5f5" colspan="6">
             
         </td>
          </tr>
</table>








                    <style>
                     .txt {
                      font-weight:bold
                     }

                     .line {
                         width: 60px;
                         border: 0px;
                         border-bottom: solid 1px #000;
                     }

                     .price td, .price th {
                         text-align:center; 
                         vertical-align:middle; 
                     }
                 </style>




                 <table class="table table-bordered price">
                     <tr  >
                         <th rowspan="2" class="tdheader" width="150px">
                             项目
                         </th>

                         <th rowspan="2"  class="tdheader" width="150px">
                            材料费（M） 
                         </th>


                      
                          <th  colspan="2"   class="tdheader"  >
                              工时费用（H）  
                         </th>




                         <th rowspan="2"  class="tdheader" width="150px">
                             管理费<br />
                             G= (M+H)*R 
                         </th>

                           <th rowspan="2"  class="tdheader" width="150px">
                               利润费<br />
                                P= (M+H)*R  
                          </th>

    <th rowspan="2"  class="tdheader" width="150px">
                              调整费<br />
          A= (M+H)*R 
                          </th>


                         <th rowspan="2"  class="tdheader" width="180px">
                             BOM单价  <br />
                             (P=M+H+G+P+A) 
                             &nbsp;&nbsp;&nbsp;&nbsp;
                           
                         </th>

                     </tr>



                     <tr>
                       
                         
                           <td style="font-size:10px;  font-weight:bold"  width="100px" >
                             工时 
                         </td>
                        <td style="font-size:10px; font-weight:bold" width="100px">
                             工时费用
                         </td>


                     </tr>









                     <tr class="rate">
                         <th>
                             费率(R）
                         </th>

                         <td>
                              --
                         </td>


                         <td>
  <asp:TextBox id="workhour" Runat="Server"      CssClass="line txt"  Width="80px"   ></asp:TextBox>
                         </td>

                         
                         <td>
 <asp:TextBox id="workprice" Runat="Server"   CssClass="line txt"  Width="80px"   ></asp:TextBox>
                         </td>

                           <td>
                               <asp:TextBox id="mgrrate" Runat="Server"   CssClass="line txt"  ></asp:TextBox> %
                         </td>

                           <td>
                               <asp:TextBox id="profitrate" Runat="Server"    CssClass="line txt"   ></asp:TextBox> %
                         </td>

                        
                            <td>
                               <asp:TextBox id="adjustrate" Runat="Server"   CssClass="line txt"  ></asp:TextBox> %
                          </td>
                         <td>
                             &nbsp;--
                         </td>
                     </tr>







<tr >
                        <th>费用</th>

                        <td  >
                             <asp:TextBox       CssClass="line txt"  ID="materialfee"  Width="120px" runat="server"></asp:TextBox>
                       </td>

                          <td colspan="2"  >
                                <asp:TextBox    style="color:gray; border-bottom-color:gray"  ReadOnly="true"  CssClass="line"  ID="workfee"  Width="120px"   runat="server"></asp:TextBox>
                          </td>




                          <td >
                             <asp:TextBox  style="color:gray; border-bottom-color:gray;"  ReadOnly="true"  CssClass="line"  ID="mgrfee"  Width="120px"   runat="server"></asp:TextBox>
                          </td>
     
                          <td>
                             <asp:TextBox       ReadOnly="true"  style="color:gray; border-bottom-color:gray"  CssClass="line"  ID="profitfee"   Width="120px"  runat="server"></asp:TextBox>
                          </td>

                            <td>
                               <asp:TextBox id="adjustfee" ReadOnly="true" Runat="Server"  Width="120" style="color:gray; border-bottom-color:gray"  CssClass="line"  ></asp:TextBox> 
                          </td>


                        <td>
                            <asp:TextBox     ReadOnly="true"    style="color:red; border-bottom-color:gray"    CssClass="line txt"  Width="120px"  ID="price"  runat="server"></asp:TextBox>
                        </td>

                    </tr>



                    <tr>

                        <td colspan="2">
                       <span style="color:#ff0000; font-weight:bold">

                     <asp:Label runat="server" ID="lbl_tip"></asp:Label>

                           <asp:PlaceHolder runat="server" ID="ph_fix" Visible="false">

                         
                             <a href="###" onclick="Pop('fix_material_price.aspx?id=<%=Request.QueryString["id"] %>',400,300,'修正价格')"  class="btn btn-info btn-sm" >修正材料费</a>
                             </asp:PlaceHolder>
                                 </span>
                        </td>

                        <td colspan="6"  style="text-align:right">

                            <a href="###" onclick="Pop('cale/cal_rate.aspx',1200,500,'费率计算器');"  class="btn btn-info btn-sm">费率计算器</a>

                            &nbsp;&nbsp;|&nbsp;&nbsp;
                            <a href="###"  onclick=" Pop('../javascript/cal/index.html',400,600,'普通计算器');" class="btn btn-info btn-sm">普通计算器</a>
                        </td>

                    </tr>

                 </table>


            <style>
                .pr{
                      

                }
            </style>

   


                </asp:Panel>

    
     
     
       
       <asp:HiddenField runat="server" ClientIDMode="Static" ID="hf_itemprice" />




     <script>

         $(".price input").change(
             function()
             {
                 calTotalPrice();
             }
             );


  




         function calTotalPrice()
         {  
             var _s = G("materialfee") + G("workhour") * G("workprice");

             var _p=_s * ( 100+   G("mgrrate")  + G("profitrate")  + G("adjustrate"));

             $("#workfee").val((G("workhour") * G("workprice")).toFixed(2));

             $("#mgrfee").val((_s * G("mgrrate") / 100.0).toFixed(2));

             $("#profitfee").val((_s * G("profitrate") / 100.0).toFixed(2));

             $("#adjustfee").val((_s * G("adjustrate") / 100.0).toFixed(2));


             _p = _p / 100.0;

             $("#price").val(_p.toFixed(2)); 
         }


         function G(_id)
         { 
             return  parseFloat(  $("#"+_id).val());
         }

     </script>














          
         <div class="text-center">

             <asp:Button runat="server" ID="btn_save" Text="保存"  ValidationGroup="Add" class="  btn btn-success btn-flat  " OnClick="btn_save_Click" />
                
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                 <asp:button  Text="删 除" OnClientClick="return confirm('确定删除吗？')" runat=server ID="delete"   CausesValidation="false"   class="  btn btn-danger btn-flat  " 
                   onclick="delete_Click" />

               &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


                 <a href="nextstep.aspx?id=<%=Request.QueryString["id"] %>&t=quote" class="btn btn-primary ">提交审批</a>
                         
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
             <a href="###" onclick="Pop('ept_price_1.aspx?id=<%=Request.QueryString["id"] %>')">导出总价</a>
             
                 <a href="###" onclick="Pop('ept_price_2.aspx?id=<%=Request.QueryString["id"] %>')">导出明细</a>          
                                 

         </div>

      </div>



           <br /><br /><br /><br />


             <style>
            .hdbody {
             overflow:hidden;
            }
        </style>


           <script>

               function disablescroll() {
                   $("body").addClass("hdbody");
                   // document.body.style.position = "fixed";
               }

               function enablescroll() {
                   $("body").removeClass("hdbody");
               }


               
               function openprice(id) {
                   url = "price_adjust.aspx?id=" + id;
                   disablescroll();
                   layer.open({
                       type: 2,
                       title: "调整价格",
                       area: ['1080px', '680px'],
                       fix: false, //不固定
                       maxmin: true,
                       content: url,
                       cancel: function (index) {
                           enablescroll();

                       }
                   }
                   );
               }

           </script>


     <div   style="border:0px; padding-bottom:5px; text-align:right; padding-right:10px; border-bottom:solid 1px #ccc">
         

  <h4 class="border-active subnav" style="float:left" ><%=isen?"Item List":"子件列表" %>   </h4>


        
             <a href="###" class="btn btn-danger btn-sm" 
               onclick="openprice(<%=Request.QueryString["id"] %>)">
                调整价格    </a>
         
         
           <asp:PlaceHolder runat="server" ID="ph_additem"  >


       
             &nbsp;&nbsp;|&nbsp;&nbsp;

           <a href="###" class="btn btn-success btn-sm" 
               onclick="Pop('copy_quote_1.aspx?quoteid=<%=Request.QueryString["id"] %>',600,550,'复制报价单')">
                <%=isen?"Copy Quote":"复制报价单" %>    </a>

                 &nbsp;&nbsp;|&nbsp;&nbsp;
               
             
              
                <a href="define_quote_price.aspx?id=<%=Request.QueryString["id"] %>&customercode=<%=_customercode %>" class="btn btn-danger btn-sm"  target="_blank"> 定义物料价格    </a>
   

               </asp:PlaceHolder>   
         
         
         
         
         
         
         
         
         
           </div>

   





















           <style>
               .detail input {
                width:80px
               }
           </style>






                  <asp:UpdatePanel ID="UpdatePanel1" runat="server" ClientIDMode="AutoID">
        <ContentTemplate>

     <asp:GridView runat="server" ID="gv_items" style=" border-collapse:collapse"  
          GridLines="None" CssClass="table table-bordered table-hover detail" 
          ShowFooter="true"   ClientIDMode="AutoID" 
              onrowdatabound="gv_applist_RowDataBound"  
         AutoGenerateColumns="False" DataSourceID="sds" DataKeyNames="id" >

         <Columns>
            
          
            <asp:BoundField DataField="ItemCode" HeaderText="子件编号" ReadOnly="true"  HeaderStyle-Width="90px"/>
            <asp:BoundField DataField="ItemName" HeaderText="子件名称"  ReadOnly="true"  HeaderStyle-Width="160px"/>
 
            <asp:BoundField DataField="spec" HeaderText="规格" ReadOnly="true"  HeaderStyle-Width="180px"/>
 
               <asp:BoundField DataField="MPN" HeaderText="厂商号" ReadOnly="true"  HeaderStyle-Width="150px"/>

             <asp:BoundField DataField="Manufacturer" HeaderText="制造商" ReadOnly="true"  HeaderStyle-Width="100px"/>
           
         
                <asp:BoundField DataField="EnvProject" HeaderText="是否环保"  ReadOnly="true"  HeaderStyle-Width="150px"/>

                     
             <asp:BoundField DataField="uom" HeaderText="单位" ReadOnly="true"  HeaderStyle-Width="80px"/>


             
              <asp:BoundField DataField="supplycode" HeaderText="供应商号" HeaderStyle-Width="80px"/> 

             <asp:BoundField DataField="supplyname" HeaderText="供应商名" HeaderStyle-Width="80px"/> 

              
          
             <asp:BoundField DataField="LeadTime" HeaderText="LeadTime" HeaderStyle-Width="100px"/>

          


              <asp:BoundField DataField="quantity" HeaderText="数量" DataFormatString="{0:N2}" HeaderStyle-Width="100px"/> 

            
             <asp:BoundField DataField="currency" HeaderText="货币" HeaderStyle-Width="80px"/>

                 <asp:BoundField DataField="price" HeaderText="报价价格" DataFormatString="{0:N2}" HeaderStyle-Width="80px"/>

             
                 <asp:BoundField DataField="subtotal" HeaderText="合计" ReadOnly="true" DataFormatString="{0:N2}" HeaderStyle-Width="120px"/>

                
            
                  

              
              <asp:CommandField ShowDeleteButton="false" ShowEditButton="True"  HeaderStyle-Width="100px"  Visible="true"/>

           
         </Columns>





     </asp:GridView>

    
     
     
     



       








           <asp:SqlDataSource runat="server" ID="sds"
               
                ConnectionString="<%$ConnectionStrings:ConnectionString %>"
               UpdateCommand="update purchase_quote_items set supplycode=@supplycode, supplyname=@supplyname, leadtime=@leadtime,quantity=@quantity,price=@price,currency=@currency where id=@id "
                SelectCommand=" select *, quantity*price as subtotal from purchase_quote_items where quoteid=@quoteid"
               >
               <SelectParameters>
                   <asp:QueryStringParameter Name="quoteid" QueryStringField="id" />

               </SelectParameters>


           </asp:SqlDataSource>



        </ContentTemplate>

    </asp:UpdatePanel>


           </div>
        </div>
   










































    <script>

        function setPopProductCode(_v)
        {

            $("#key").val(_v);
        }


        $("#mprice").html($("#hf_itemprice").val());
    </script>

</asp:Content>
