Exemple #1
0
        /// <summary>
        /// Deletes the ExportHeader with the specified BatchNo and its Children.
        /// </summary>
        /// <param name="batchNo"></param>
        /// <returns></returns>
        public bool Delete(int batchNo)
        {
            Logger.DebugFormat("+Enter");
            try
            {
                if (!(CanDelete(batchNo)))
                {
                    return(false);
                }

                ExportHeader exportHeader;
                if (Read(out exportHeader, batchNo))
                {
                    var list = ContextSharedPickup.PickupAccountingRow.Where(t => t.Fk_ExportHeader_Id == exportHeader.Id).ToList();
                    ContextSharedPickup.PickupAccountingRow.RemoveRange(list);
                    ContextSharedPickup.ExportHeader.Remove(exportHeader);
                    ContextSharedPickup.SaveChanges();
                    return(true);
                }

                return(false);
            }

            finally
            {
                Logger.DebugFormat("-Exit");
            }
        }
Exemple #2
0
        private bool ChangeStatus(int batchNo, ExportStatus newStatus)
        {
            ExportHeader exportHeader;

            if (Read(out exportHeader, batchNo))
            {
                var before = exportHeader.ExportStatus;
                exportHeader.ExportStatus = newStatus;
                var msg = String.Format("{0:yyyy-MM-dd HH:mm}, {1:G} -> {2:G}", SystemDateTime.Now, before, newStatus);
                exportHeader.HistoryLog = "; ".Concatenate(exportHeader.HistoryLog, msg);
                ContextSharedPickup.SaveChanges();
                return(true);
            }

            return(false);
        }
Exemple #3
0
        // ReSharper disable once UnusedMethodReturnValue.Local
        private bool Create(out ExportHeader value, string historyLog, string requestor)
        {
            Logger.DebugFormat("+Enter");
            try
            {
                var websiteId = DbMainStandard.CurrentWebsite.First().ApplicationId;

                var batchNo =
                    ContextSharedPickup.ExportHeader.Any(
                        t => t.Name.Equals(ExportName, StringComparison.OrdinalIgnoreCase))
                        ? ContextSharedPickup.ExportHeader.Where(
                        t => t.Name.Equals(ExportName, StringComparison.OrdinalIgnoreCase)).Max(t => t.BatchNo) + 1
                        : 1;

                value = ContextSharedPickup.ExportHeader.Add(new ExportHeader
                {
                    BatchNo         = batchNo,
                    ExportStatus    = ExportStatus.Requested,
                    HistoryLog      = historyLog,
                    Name            = ExportName,
                    Requestor       = requestor,
                    RowCount        = 0,
                    TimestampCreate = SystemDateTime.UtcNow,
                    WebsiteId       = websiteId,
                    WebsiteIdHash   = websiteId.GetHashCode()
                });
                ContextSharedPickup.SaveChanges();

                return(true);
            }

            finally
            {
                Logger.DebugFormat("-Exit");
            }
        }
Exemple #4
0
        /// <summary>
        /// Select data not previously selected on any PickupAccounting report.
        /// </summary>
        /// <returns></returns>
        public int SelectData(out ExportHeader exportHeader, DateTime from, DateTime until, string requestor)
        {
            Logger.DebugFormat("+Enter");
            try
            {
                if (from > until)
                {
                    throw new GtxClientException("from > until", "XuFromError2", new object[] { "from > until" });
                }
                //if (until > SystemDateTime.Yesterday) { throw new GtxClientException("Illegal until date", "XuUntilError2", new object[] { SystemDateTime.Yesterday }); }
                if (until > SystemDateTime.Today)
                {
                    throw new GtxClientException("Illegal until date", "XuUntilError2", new object[] { SystemDateTime.Today });
                }                                                                                                                                                 // TODO use yesteday

                Create(out exportHeader, String.Format("From: {0:yyyy-MM-dd} until: {1:yyyy-MM-dd}", from, until), requestor);

                const string sql =
                    "SELECT "
                    + "Pickup.CustomerPickup.Id "
                    + "FROM "
                    + "Pickup.CustomerPickup "
                    + "LEFT OUTER JOIN "
                    + "Pickup.PickupAccountingRow "
                    + "ON Pickup.CustomerPickup.Id = Pickup.PickupAccountingRow.FK_CustomerPickup_Id "
                    + "WHERE "
                    + "{0} <= Pickup.CustomerPickup.PickupDate "
                    + "and "
                    + "Pickup.CustomerPickup.PickupDate <= {1} "
                    + "and "
                    + "Pickup.CustomerPickup.PickupStatus != N'CustHand' " // TODO maybe som kind of closed or finished
                    + "and "
                    + "Pickup.PickupAccountingRow.Id IS NULL "             // not part in any existing report.
                ;

                var sqlCommand = ContextSharedPickup.Database.SqlQuery <int>(sql, from, until);

                var rowList = sqlCommand.ToList();

                var count = 0;

                foreach (var customerPickupId in rowList)
                {
                    ContextSharedPickup.PickupAccountingRow.Add(new PickupAccountingRow
                    {
                        ExportData           = String.Empty,
                        FK_CustomerPickup_Id = customerPickupId,
                        Fk_ExportHeader_Id   = exportHeader.Id,
                        Sorting = String.Empty
                    }
                                                                );
                    count++;
                }

                exportHeader.RowCount = count;

                if (count == 0)
                {
                    ContextSharedPickup.ExportHeader.Remove(exportHeader);
                }

                ContextSharedPickup.SaveChanges();

                return(count);
            }

            finally
            {
                Logger.DebugFormat("-Exit");
            }
        }
Exemple #5
0
        /// <summary>
        /// Calculates the ExportRow for each selected CustomerPickup, result is saved in PickupAccountingRow.ExportData.
        /// </summary>
        /// <param name="exportHeader"></param>
        /// <param name="host"></param>
        /// <returns></returns>
        public int CalculatePickupAccountingRow(ExportHeader exportHeader, Uri host)
        {
            Logger.DebugFormat("+Enter");
            try
            {
                var pickupAccountingRows = ContextSharedPickup.PickupAccountingRow.Where(t => t.Fk_ExportHeader_Id == exportHeader.Id).ToList();

                foreach (var pickupAccountingRow in pickupAccountingRows)
                {
                    pickupAccountingRow.ExportData = String.Empty;
                    pickupAccountingRow.Sorting    = String.Empty;
                    ContextSharedPickup.SaveChanges();
                }

                foreach (var pickupAccountingRow in pickupAccountingRows)
                {
                    var customerPickup = ContextSharedPickup.CustomerPickup.Include(t => t.ForwarderPickup).FirstOrDefault(
                        t =>
                        t.Id == pickupAccountingRow.FK_CustomerPickup_Id
                        );

                    if (customerPickup == null)
                    {
                        continue;
                    }
                    if (customerPickup.ForwarderPickup == null)
                    {
                        Logger.ErrorFormat("Orphan CustomerPickup.Id: {0}", customerPickup.Id);
                        continue;
                    }

                    DataExportRow1 exportRow;
                    if (Convert(out exportRow, customerPickup))
                    {
                        var row = Converter.ConvertRow(exportRow, host);
                        pickupAccountingRow.ExportData = row;
                        pickupAccountingRow.Sorting    = String.Format(
                            "{0:yyyy-MM-dd};{1,8};{2,8};{3,8},{4,8}"
                            , customerPickup.PickupDate
                            , customerPickup.FK_Customer_Id
                            , customerPickup.DebitorAccount
                            , customerPickup.Address.Zip
                            , customerPickup.Id
                            );
                    }

                    ContextSharedPickup.SaveChanges();
                }

                exportHeader.HistoryLog = "; ".Concatenate(exportHeader.HistoryLog, String.Format("{0:yyyy-MM-dd HH:mm} Calculated", SystemDateTime.Now));

                if (exportHeader.ExportStatus == ExportStatus.Requested)
                {
                    exportHeader.ExportStatus = ExportStatus.Calculated;
                }

                ContextSharedPickup.SaveChanges();

                return(0);
            }

            finally
            {
                Logger.DebugFormat("-Exit");
            }
        }