//public ActionResult ISR110_GetRptDeliveryConfirmData(string strSlipNo)
        //{
        //    strSlipNo = "401029201112043";
        //    IReportHandler reportHandler = ServiceContainer.GetService<IReportHandler>() as IReportHandler;
        //    List<RPTDeliveryConfirmDo> rptList = reportHandler.GetRptDeliveryConfirmData(strSlipNo);

        //    IDocumentHandler dochandler = ServiceContainer.GetService<IDocumentHandler>() as IDocumentHandler;
        //    List<tbm_DocumentTemplate> dLst = dochandler.GetDocumentTemplateByDocumentCode(DocumentCode.C_DOCUMENT_CODE_DELIVERY_CONFIRMATION_AND_WARRANTY);

        //    ReportDocument rptH = new ReportDocument();

        //    string path = ReportUtil.GetReportPath("Reports/ISR110_DeliveryConfirmData.rpt", Server.MapPath("/"));

        //    rptH.Load(path);

        //    List<RPTDeliveryConfirmDo> lst = new List<RPTDeliveryConfirmDo>();
        //    int i = 0;
        //    foreach (RPTDeliveryConfirmDo rptDataRow in rptList)
        //    {
        //        lst.Add(rptDataRow);
        //        if (dLst.Count > 0)
        //        {
        //            lst[i].DocumentNameEN = dLst[0].DocumentNameEN;
        //            lst[i].DocumentVersion = dLst[0].DocumentVersion;
        //        }
        //        i++;
        //    }
        //    rptH.SetDataSource(lst);
        //    rptH.Subreports["Page1"].SetDataSource(lst);
        //    rptH.Subreports["Page2"].SetDataSource(lst);
        //    Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
        //    rptH.Close();

        //    return File(stream, "application/pdf");
        //}
        #endregion

        public ActionResult GenerateInstallationSlipDocBySlipNo()
        {
            ObjectResultData             res         = new ObjectResultData();
            ICommonHandler               comHandler  = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
            IInstallationDocumentHandler docHand     = ServiceContainer.GetService <IInstallationDocumentHandler>() as IInstallationDocumentHandler;
            IInstallationHandler         installHand = ServiceContainer.GetService <IInstallationHandler>() as IInstallationHandler;

            try
            {
                //using (TransactionScope scope = new TransactionScope())
                //{
                List <tbt_InstallationSlip> installList  = installHand.GetTbt_InstallationSlip(null);
                List <tbt_DocumentList>     documentList = comHandler.GetTbt_DocumentList(null, null, null);

                installList = (from t in installList
                               where //(
                                     //t.SlipStatus == "01"
                                     //|| t.SlipStatus == "02"
                                     //|| t.SlipStatus == "03"
                                     //|| t.SlipStatus == "04"
                                     //|| t.SlipStatus == "06")
                                     //&& t.SlipIssueFlag == true
                                     //&& t.CreateDate >= new DateTime(2013,7,24,12,20,0)
                               t.CreateBy == "INITIAL" &&
                               documentList.Any(d => (d.DocumentNo == t.SlipNo))
                               select t).ToList <tbt_InstallationSlip>();

                foreach (tbt_InstallationSlip data in installList)
                {
                    tbt_InstallationSlip dataSlip = installHand.GetTbt_InstallationSlipData(data.SlipNo);

                    //if (dataSlip != null
                    //        && dataSlip.SlipStatus != SlipStatus.C_SLIP_STATUS_NO_NEED_TO_STOCK_OUT
                    //        && dataSlip.SlipStatus != SlipStatus.C_SLIP_STATUS_NOT_STOCK_OUT //Modify by Jutarat A. on 07022013
                    //        && dataSlip.SlipStatus != SlipStatus.C_SLIP_STATUS_PARTIAL_STOCK_OUT //Add by Jutarat A. on 17062013
                    //        && dataSlip.SlipStatus != SlipStatus.C_SLIP_STATUS_STOCK_OUT) //Add by Jutarat A. on 24062013
                    //{
                    //    return Json(res);
                    //}

                    if (dataSlip.InstallationType == RentalInstallationType.C_RENTAL_INSTALL_TYPE_NEW || dataSlip.InstallationType == RentalInstallationType.C_RENTAL_INSTALL_TYPE_CHANGEPLAN_NEW)
                    {
                        //6.1.1.	Call		InstallationDocumentHandler.CreateISR010
                        //Parameter	doTbt_InstallationSlip.SlipNo
                        //Return		fsPDFFileISR010
                        docHand.CreateInstallationReport(dataSlip.SlipNo, DocumentCode.C_DOCUMENT_CODE_NEW_INSTALL_SLIP_RENTAL);
                    }

                    if (dataSlip.InstallationType == RentalInstallationType.C_RENTAL_INSTALL_TYPE_CHANGE_WIRING ||
                        dataSlip.InstallationType == RentalInstallationType.C_RENTAL_INSTALL_TYPE_CHANGEPLAN_AFTER_NEW ||
                        dataSlip.InstallationType == RentalInstallationType.C_RENTAL_INSTALL_TYPE_MAINTENANCE_EXCHANGE ||
                        dataSlip.InstallationType == RentalInstallationType.C_RENTAL_INSTALL_TYPE_MOVE ||
                        dataSlip.InstallationType == RentalInstallationType.C_RENTAL_INSTALL_TYPE_PERIODICAL_MAINTENANCE ||
                        dataSlip.InstallationType == RentalInstallationType.C_RENTAL_INSTALL_TYPE_REMOVE_DURING_STOP_PARTIAL ||
                        dataSlip.InstallationType == RentalInstallationType.C_RENTAL_INSTALL_TYPE_REMOVE_DURING_STOP_REMOVE_ALL ||
                        dataSlip.InstallationType == SaleInstallationType.C_SALE_INSTALL_TYPE_CHANGE_WIRING ||
                        dataSlip.InstallationType == SaleInstallationType.C_SALE_INSTALL_TYPE_MAINTENANCE_EXCHANGE ||
                        dataSlip.InstallationType == SaleInstallationType.C_SALE_INSTALL_TYPE_MOVE ||
                        dataSlip.InstallationType == SaleInstallationType.C_SALE_INSTALL_TYPE_PARTIAL_REMOVE
                        )
                    {
                        //6.2.1.	Call		InstallationDocumentHandler.CreateISR020
                        //Parameter	doTbt_InstallationSlip.SlipNo
                        //Return		fsPDFFileISR020
                        docHand.CreateInstallationReport(dataSlip.SlipNo, DocumentCode.C_DOCUMENT_CODE_CHANGE_INSTALL_SLIP);
                    }
                    if (dataSlip.InstallationType == RentalInstallationType.C_RENTAL_INSTALL_TYPE_REMOVE_ALL ||
                        dataSlip.InstallationType == SaleInstallationType.C_SALE_INSTALL_TYPE_REMOVE_ALL)
                    {
                        //6.3.1.	Call		InstallationDocumentHandler.CreateISR030
                        //Parameter	doTbt_InstallationSlip.SlipNo
                        //Return		fsPDFFileISR030
                        docHand.CreateInstallationReport(dataSlip.SlipNo, DocumentCode.C_DOCUMENT_CODE_REMOVAL_INSTALL_SLIP);
                    }
                    if (dataSlip.InstallationType == SaleInstallationType.C_SALE_INSTALL_TYPE_NEW ||
                        dataSlip.InstallationType == SaleInstallationType.C_SALE_INSTALL_TYPE_ADD)
                    {
                        //6.4.1.	Call		InstallationDocumentHandler.CreateISR040
                        //Parameter	doTbt_InstallationSlip.SlipNo
                        //Return		fsPDFFileISR040
                        docHand.CreateInstallationReport(dataSlip.SlipNo, DocumentCode.C_DOCUMENT_CODE_NEW_INSTALL_SLIP_SALE);
                    }

                    if (dataSlip != null && dataSlip.SlipIssueFlag != FlagType.C_FLAG_ON)
                    {
                        dataSlip.SlipIssueFlag = FlagType.C_FLAG_ON;
                        int updatedRpw = installHand.UpdateTbt_InstallationSlip(dataSlip);
                    }
                }

                //    scope.Complete();
                //    res.ResultData = "Process Complete.";
                //}

                res.ResultData = "Process Complete.";
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }
        public ActionResult BLP030_ManageInvoiceProcessTemp()
        {
            ObjectResultData        res                    = new ObjectResultData();
            IBillingHandler         billingHandler         = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;
            ICommonHandler          comHandler             = ServiceContainer.GetService <ICommonHandler>() as ICommonHandler;
            IBillingDocumentHandler billingDocumentHandler = ServiceContainer.GetService <IBillingDocumentHandler>() as IBillingDocumentHandler;

            try
            {
                //using (TransactionScope scope = new TransactionScope())
                //{
                List <tbt_Invoice>      invoiceList  = billingHandler.GetTbt_Invoice(null, null);
                List <tbt_DocumentList> documentList = comHandler.GetTbt_DocumentList(null, null, null);

                invoiceList = (from t in invoiceList
                               where
                               //t.CreateBy == "BLP030"
                               //&& t.InvoicePaymentStatus != "08"
                               //&&
                               t.CreateDate <= new DateTime(2013, 6, 21) &&
                               t.CreateDate > new DateTime(2013, 6, 20) &&
                               !documentList.Any(d => (d.DocumentNo == t.InvoiceNo))
                               select t).ToList <tbt_Invoice>();

                foreach (tbt_Invoice data in invoiceList)
                {
                    billingDocumentHandler.GenerateBLR010FilePath(data.InvoiceNo, ProcessID.C_PROCESS_ID_MANAGE_INVOICE, data.CreateDate.Value);
                }


                // Comment by Jirawat Jannet
                //List<tbt_TaxInvoice> taxInvoiceList = billingHandler.GetTbt_TaxInvoice(null);

                //taxInvoiceList = (from t in taxInvoiceList
                //                  where
                //                      //t.CreateBy == "BLP030"
                //                      //&&
                //                    t.CreateDate <= new DateTime(2013, 6, 21)
                //                    && t.CreateDate > new DateTime(2013, 6, 20)
                //                    && !documentList.Any(d => (d.DocumentNo == t.TaxInvoiceNo))
                //                  select t).ToList<tbt_TaxInvoice>();

                // Comment by Jirawat Jannet
                //foreach (tbt_TaxInvoice data in taxInvoiceList)
                //{
                //    billingDocumentHandler.GenerateBLR020FilePath(data.TaxInvoiceNo, ProcessID.C_PROCESS_ID_MANAGE_INVOICE, data.CreateDate.Value);
                //}


                //    scope.Complete();
                //    res.ResultData = "Process Complete.";
                //}

                res.ResultData = "Process Complete.";
            }
            catch (Exception ex)
            {
                res.AddErrorMessage(ex);
            }

            return(Json(res));
        }