@model Com._9pm2.ClientWeb.Models.PrintFactoryDeliveryModel
@{Layout = null;}
@{
    ViewBag.Title = "外协单";
}
<html>
<head>
    <title>客户订单</title>
    <link rel="stylesheet" href="~/Content/print.css?vn=20180813" />
    <style id="print-css">
    div,span,td,th{      
        font-size:@Model.Settings.PrintCommonFontSize ;
    }
    </style>
    <style>
          body{
        padding:@Model.Settings.PrintCommonMarginCss ;
        }
    </style>
    <script src="../../Scripts/jquery-1.11.2.min.js"></script>
    <script language="javascript" src="~/Content/Lodop/LodopFuncs.js?vn=20180813"></script>
    <script>
        var LODOP; //声明为全局变量

        function PreviewMytable() {
            LODOP = getLodop();

            $.get("/Content/print.css?vn=20180813", function (result) {

                var strInnerStyle = document.getElementById("print-css").innerHTML;
                var strBodyStyle = "<style>" + result + strInnerStyle + "</style>";
                var strBodyHtml = strBodyStyle + "<body>" + document.getElementById("print-content").innerHTML + "</body>";

                LODOP.PRINT_INIT("九平米外协单打印");
                LODOP.ADD_PRINT_HTM(0, 0, "100%", "100%", strBodyHtml);

                var margins = document.getElementById("hidMargin").value;
                var marginList = margins.split(" ");
                console.log(marginList);
                if (marginList.length > 0) {
                    LODOP.SET_PRINT_STYLEA(0, 'Top', marginList[0]);
                }
                if (marginList.length > 3) {
                    LODOP.SET_PRINT_STYLEA(0, 'Left', marginList[3]);
                }
                if (marginList.length > 2) {
                    LODOP.SET_PRINT_STYLEA(0, 'Height', 'BottomMargin:' + marginList[2]);
                }
                if (marginList.length > 1) {
                    LODOP.SET_PRINT_STYLEA(0, 'Width', 'RightMargin:' + marginList[1]);
                }

                LODOP.PREVIEW();
            });
        };

    </script>
</head>

<body>
    <p id="p-print">
        <a href="javascript:PreviewMytable();" id="btnPrint">精细打印</a>&nbsp;
        <a href="#" id="btnHtmlPrint" onclick="PrintHtmlPage()">网页打印</a>
    </p>
    <input type="hidden" id="hidMargin" value="@Model.Settings.PrintCommonMarginCss" />

    <div class="container" id="print-content">


        <table class="head">
            <tr>
                <td>
                    <div class="title">
                        <div class="page-title">@Model.Settings.CompanyNameOnReport [外协单]</div>
                        <div class="c-info">
                            <div>
                                公司地址：@Model.Settings.AddressOnReport
                            </div>
                            <div class="contact">
                                <div>
                                    联系电话：@Model.Settings.PhoneFaxOnReport
                                </div>

                                <div>
                                    打印时间：@DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                </div>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </table>         

        <div class="hr"></div>

        <table class="no-border-table">
            <tr>
                <td>
                    外协商：@Model.Orders[0].FactoryOrder.Factory.FactoryName
                </td>
                <td>
                    联系人：@Model.Orders[0].FactoryOrder.Contact
                </td>
            </tr>
        </table>

        <table class="data-table">
            <thead>
                <tr>
                    @if (Model.Settings.PrintDeliveryOrderNo)
                    {
                        <th>订单号</th>
                    }
                    @if (Model.Settings.PrintDeliveryCategory)
                    {
                        <th>业务类型</th>
                    }
                    <th style="min-width:70px">名称</th>

                    <th>明细</th>

                    @if (Model.Settings.PrintDeliveryUnit)
                    {
                        <th style="width:50px">单位</th>
                    }
                    <th style="width:50px">数量</th>
                    <th style="width:60px">单价</th>
                    <th style="width:60px">金额</th>
                    @if (Model.Settings.PrintDeliveryMemo)
                    {
                        <th>备注</th>
                    }
                </tr>
            </thead>
            <tbody>
                @foreach (Com._9pm2.ClientWeb.Database.FactoryOrderDetail o in Model.Orders)
                {
                    <tr>
                        @if (Model.Settings.PrintDeliveryOrderNo)
                        {
                            <td>@o.FactoryOrderNo</td>
                        }
                        @if (Model.Settings.PrintDeliveryCategory)
                        {
                            <td>@o.Category</td>
                        }

                        <td>@o.OrderName</td>
                        <td>@(string.IsNullOrEmpty(o.TechnicText) ? o.DetailText : (string.IsNullOrEmpty(o.DetailText) ? "工艺: " : o.DetailText + ", 工艺: ") + o.TechnicText)</td>
                        @if (Model.Settings.PrintDeliveryUnit)
                        {
                            <td>@(o.PriceUnit == null ? "" : o.PriceUnit.Name)</td>
                        }
                        <td class="aright">@Com._9pm2.ClientWeb.Utilities.NFormat.Fix0or2Decimal(o.Number)</td>
                        <td class="aright">@Com._9pm2.ClientWeb.Utilities.NFormat.Fix2or4Decimal(o.Price)</td>
                        <td class="aright">@string.Format("{0:F2}", o.Amount)</td>
                        @if (Model.Settings.PrintDeliveryMemo)
                        {
                            <td>@o.Memo</td>
                        }
                    </tr>
                }

                @if (Model.Settings.PrintDeliveryEmptyRow)
                {
                    for (int i = Model.Settings.PrintDeliveryEmptyRowNumber; i > Model.Orders.Count; i--)
                    {
                        <tr>
                            @for (int j = 0; j < Model.ColumnCount; j++)
                            {
                                <td></td>
                            }
                        </tr>
                    }
                }


                <tr>
                    <td class="tr-total" colspan="@Model.ColumnCount">
                        @if (Model.FeeInstallation > 0)
                        {
                            <span>安装费：@string.Format("{0:0.00}", Model.FeeInstallation)</span>
                        }
                        @if (Model.FeeDelivery > 0)
                        {
                            <span>送货费：@string.Format("{0:0.00}", Model.FeeDelivery)</span>
                        }
                        @if (Model.FeeDesign > 0)
                        {
                            <span>设计费：@string.Format("{0:0.00}", Model.FeeDesign)</span>
                        }
                        @if (Model.FeeOther > 0)
                        {
                            <span>其它费用：@string.Format("{0:0.00}", Model.FeeOther)</span>
                        }
                        <span>合计金额：@string.Format("{0:0.00}", Model.TotalMarketAmount)</span>
                        @if (Model.TotalDiscount > 0)
                        {
                            <span>折扣金额：@string.Format("{0:0.00}", Model.TotalDiscount * -1)</span>
                        }
                        <span>实际金额：@string.Format("{0:0.00}", Model.TotalAmount)</span>
                        <span>已付金额：@string.Format("{0:0.00}", Model.TotalPaid)</span>
                        <span>应付金额：@string.Format("{0:0.00}", Model.TotalUnpaid)</span>
                    </td>
                </tr>
                @if (Model.Settings.PrintDeliveryOrderMemo)
                {
                    <tr>
                        <td colspan="@Model.ColumnCount">备注：@Model.OrderMemo</td>
                    </tr>
                }

            </tbody>
        </table>



    </div>
    <script>
        if (location.href.indexOf("flag") > 0) {
            document.getElementById("p-print").style.display = "none";
        }

       
    </script>

</body>
</html>
