Commit 3ff5c8d6 by Elias Sarraf

Merge remote-tracking branch 'origin/mac'

parents bb05403e 0565250e
......@@ -26,7 +26,6 @@ object FAddOrder: TFAddOrder
Width = 121
Height = 22
HeightPercent = 100.000000000000000000
Text = 'edtSearch'
WidthPercent = 100.000000000000000000
OnChange = edtSearchChange
end
......@@ -37,14 +36,14 @@ object FAddOrder: TFAddOrder
Height = 22
ChildOrder = 1
HeightPercent = 100.000000000000000000
Text = 'WebEdit1'
WidthPercent = 100.000000000000000000
end
object TMSFNCGrid1: TTMSFNCGrid
Left = 0
Top = 166
Top = 146
Width = 871
Height = 303
Height = 331
Align = alBottom
ParentDoubleBuffered = False
DoubleBuffered = True
TabOrder = 2
......@@ -242,13 +241,13 @@ object FAddOrder: TFAddOrder
end
object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 728
Top = 109
Left = 730
Top = 93
end
object xdwdsCustomers: TXDataWebDataSet
Connection = DMConnection.ApiConnection
Left = 600
Top = 109
Top = 95
object xdwdsCustomersID: TIntegerField
FieldName = 'ID'
end
......@@ -265,7 +264,7 @@ object FAddOrder: TFAddOrder
end
object wdsCustomers: TWebDataSource
DataSet = xdwdsCustomers
Left = 470
Top = 109
Left = 468
Top = 93
end
end
......@@ -12,8 +12,8 @@ object FViewOrders: TFViewOrders
OnCreate = WebFormCreate
OnShow = WebFormShow
object lblEntries: TWebLabel
Left = 68
Top = 333
Left = 59
Top = 113
Width = 77
Height = 13
Caption = 'Showing 0 of ...'
......@@ -207,8 +207,8 @@ object FViewOrders: TFViewOrders
TabStop = False
WidthPercent = 100.000000000000000000
end
object WebButton2: TWebButton
Left = 328
object btnPDF: TWebButton
Left = 332
Top = 79
Width = 96
Height = 25
......@@ -221,73 +221,181 @@ object FViewOrders: TFViewOrders
TabOrder = 8
TabStop = False
WidthPercent = 100.000000000000000000
OnClick = btnPDFClick
end
object wdbtcOrders: TWebDBTableControl
Left = 26
Top = 132
Width = 631
Height = 200
ElementClassName = 'table'
ElementId = 'tblPhoneGrid'
BorderColor = clSilver
ChildOrder = 11
ElementFont = efCSS
ElementHeaderClassName = 'thead-light'
ElementPosition = epRelative
ElementTableClassName = 'table table-striped table-hover table-bordered text-sm'
Footer.ButtonActiveElementClassName = 'btn btn-primary'
Footer.ButtonElementClassName = 'btn btn-light'
Footer.DropDownElementClassName = 'form-control'
Footer.InputElementClassName = 'form-control'
Footer.LinkActiveElementClassName = 'link-primary'
Footer.LinkElementClassName = 'link-secondary'
Footer.ListElementClassName = 'pagination'
Footer.ListItemElementClassName = 'page-item'
Footer.ListLinkElementClassName = 'page-link'
Header.ButtonActiveElementClassName = 'btn btn-primary'
Header.ButtonElementClassName = 'btn btn-light'
Header.DropDownElementClassName = 'form-control'
Header.InputElementClassName = 'form-control'
Header.LinkActiveElementClassName = 'link-primary'
Header.LinkElementClassName = 'link-secondary'
Header.ListElementClassName = 'pagination'
Header.ListItemElementClassName = 'page-item'
Header.ListLinkElementClassName = 'page-link'
WordWrap = True
Columns = <
item
DataField = 'ID'
Title = 'ID'
end
item
DataField = 'companyName'
Title = 'Company Name'
end
item
DataField = 'jobName'
Title = 'Job Name'
end
item
DataField = 'orderDate'
Title = 'Order Date'
end
item
DataField = 'proofDue'
Title = 'Proof Due'
end
item
DataField = 'proofDone'
Title = 'Proof Done'
end
item
DataField = 'artDue'
Title = 'Art Due'
end
item
DataField = 'artDone'
Title = 'Art Done'
end
item
DataField = 'mountDue'
Title = 'Mount Due'
end
item
DataField = 'mountDone'
Title = 'Mount Done'
end
item
DataField = 'shipDue'
Title = 'Ship Due'
end
item
DataField = 'shipDone'
Title = 'Ship Done'
end
item
DataField = 'price'
Title = 'Price'
end
item
DataField = 'qbRefNum'
Title = 'Quickbooks Reference Number'
end
item
DataField = 'colors'
Title = 'Colors'
end
item
DataField = 'plateDue'
Title = 'Plate Due'
end
item
DataField = 'plateDone'
Title = 'Plate Done'
end
item
DataField = 'orderType'
Title = 'Order Type'
end>
DataSource = wdsOrders
end
object XDataWebClient1: TXDataWebClient
Connection = DMConnection.ApiConnection
Left = 28
Top = 410
end
object XDataWebDataSet1: TXDataWebDataSet
object xdwdsOrders: TXDataWebDataSet
Connection = DMConnection.ApiConnection
Left = 70
Top = 410
object XDataWebDataSet1ID: TStringField
object xdwdsOrdersID: TStringField
FieldName = 'ID'
end
object XDataWebDataSet1companyName: TStringField
object xdwdsOrderscompanyName: TStringField
FieldName = 'companyName'
end
object XDataWebDataSet1jobName: TStringField
object xdwdsOrdersjobName: TStringField
FieldName = 'jobName'
end
object XDataWebDataSet1orderDate: TStringField
object xdwdsOrdersorderDate: TStringField
FieldName = 'orderDate'
end
object XDataWebDataSet1proofDue: TStringField
object xdwdsOrdersproofDue: TStringField
FieldName = 'proofDue'
end
object XDataWebDataSet1proofDone: TStringField
object xdwdsOrdersproofDone: TStringField
FieldName = 'proofDone'
end
object XDataWebDataSet1artDue: TStringField
object xdwdsOrdersartDue: TStringField
FieldName = 'artDue'
end
object XDataWebDataSet1artDone: TStringField
object xdwdsOrdersartDone: TStringField
FieldName = 'artDone'
end
object XDataWebDataSet1mountDue: TStringField
object xdwdsOrdersmountDue: TStringField
FieldName = 'mountDue'
end
object XDataWebDataSet1mountDone: TStringField
object xdwdsOrdersmountDone: TStringField
FieldName = 'mountDone'
end
object XDataWebDataSet1shipDue: TStringField
object xdwdsOrdersshipDue: TStringField
FieldName = 'shipDue'
end
object XDataWebDataSet1shipDone: TStringField
object xdwdsOrdersshipDone: TStringField
FieldName = 'shipDone'
end
object XDataWebDataSet1price: TStringField
object xdwdsOrdersprice: TStringField
FieldName = 'price'
end
object XDataWebDataSet1qbRefNum: TStringField
object xdwdsOrdersqbRefNum: TStringField
FieldName = 'qbRefNum'
end
object XDataWebDataSet1colors: TStringField
object xdwdsOrderscolors: TStringField
FieldName = 'colors'
end
object XDataWebDataSet1plateDue: TStringField
object xdwdsOrdersplateDue: TStringField
FieldName = 'plateDue'
end
object XDataWebDataSet1plateDone: TStringField
object xdwdsOrdersplateDone: TStringField
FieldName = 'plateDone'
end
object XDataWebDataSet1orderType: TStringField
object xdwdsOrdersorderType: TStringField
FieldName = 'orderType'
end
end
object WebDataSource1: TWebDataSource
DataSet = XDataWebDataSet1
object wdsOrders: TWebDataSource
DataSet = xdwdsOrders
Left = 120
Top = 410
end
......
<div class="container vh-100 d-flex flex-column pb-5" style="max-width: 80%;">
<div class="container h-100 d-flex flex-column mt-0" style="max-width: 95%;">
<!-- Alert Section -->
<div class="row">
<div class="col-sm">
......@@ -46,7 +45,10 @@
<button id="btnsetstatus" class="btn btn-secondary mt-3">Set Status</button>
</div>
<div class="col-auto">
<button id="btngeneratepdf" class="btn btn-secondary mt-3">Generate PDF</button>
<button id="btngeneratepdf" class="btn btn-secondary mt-3" type="button">Generate PDF</button>
<div class="invalid-feedback">
No order selected. Please select an order to generate a PDF.
</div>
</div>
<div class="col-auto">
<button id="btnfilters" class="btn btn-secondary mt-3">Filters</button>
......@@ -54,58 +56,34 @@
</div>
</div>
<!-- Entries Label Section -->
<div class="container mt-2">
<div class="row">
<div class="col">
<div class="d-flex justify-content-between w-100 mt-2">
<label id="lblentries"></label>
</div>
</div>
</div>
<!-- Table Section -->
<div id="order_table_section" class="overflow-auto mt-2 flex-grow-1">
<div id="order_table_section" class="overflow-auto mt-2"
style="max-height: calc(100vh - 380px); border-bottom: none; padding-bottom: 0;">
<table id="tblPhoneGrid" class="table table-striped table-bordered">
<thead style="position: sticky; top: 0; z-index: 1; background-color: white; border-bottom: 2px solid #dee2e6;">
<tr>
<th>Order ID</th>
<th>Company Name</th>
<th>Job Name</th>
<th>Order Date</th>
<th>Proof Due</th>
<th>Proof Date</th>
<th>Art Due</th>
<th>Art Done</th>
<th>Plate Due</th>
<th>Plate Done</th>
<th>Mount Due</th>
<th>Mount Done</th>
<th>Ship Due</th>
<th>Ship Done</th>
<th>Price</th>
<th>QuickBooks Ref Number</th>
<th>Colors</th>
<thead class="sticky-top bg-light">
<tr style="font-size: 0.875rem;">
<!-- Table headers are dynamically generated -->
</tr>
</thead>
<tbody>
<!-- Rows will be dynamically added -->
<tbody id="orderTableBody" class="align-middle">
<!-- Table rows are dynamically generated -->
</tbody>
</table>
</div>
<!-- Pagination Section -->
<div class="container mt-4">
<div class="row justify-content-center">
<div class="d-flex justify-content-center w-100 mt-4">
<nav aria-label="Page navigation">
<ul id="pagination" class="pagination">
<!-- Pagination items added dynamically -->
</ul>
</nav>
</div>
</div>
</div>
<!-- Confirmation Modal -->
......
......@@ -279,6 +279,20 @@ input[type="text"] {
color: #fff !important;
}
.card {
border: none !important;
box-shadow: none !important; /* If shadow is causing the issue */
}
.color-column {
width: 200px; /* Fixed width for the column */
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis; /* Adds ellipsis */
}
.grid-container {
position: relative; /* Ensure the container is the reference for child positioning */
......
......@@ -47,7 +47,7 @@ object FData: TFData
object DBAdvGrid1: TDBAdvGrid
Left = 6
Top = 84
Width = 632
Width = 689
Height = 154
ColCount = 11
DrawingStyle = gdsClassic
......@@ -628,7 +628,7 @@ object FData: TFData
object DBAdvGrid2: TDBAdvGrid
Left = 6
Top = 237
Width = 631
Width = 985
Height = 199
ColCount = 20
DrawingStyle = gdsClassic
......@@ -1495,6 +1495,15 @@ object FData: TFData
TabOrder = 10
TextHint = 'Email Address'
end
object btnPDF: TButton
Left = 330
Top = 38
Width = 75
Height = 25
Caption = 'Preview PDF'
TabOrder = 11
OnClick = btnPDFClick
end
object dsUsers: TDataSource
DataSet = uqUsers
Left = 482
......
......@@ -34,14 +34,15 @@ type
edtFullName: TEdit;
edtPhoneNumber: TEdit;
edtEmailAddress: TEdit;
btnPDF: TButton;
procedure FormCreate(Sender: TObject);
procedure btnFindClick(Sender: TObject);
procedure btnPDFClick(Sender: TObject);
private
{ Private declarations }
accountSID: string;
authHeader: string;
public
{ Public declarations }
function GetReportPDF(OrderID: string): string;
end;
var
......@@ -51,7 +52,13 @@ implementation
{$R *.dfm}
uses KGOrders.Database, uLibrary;
uses KGOrders.Database, uLibrary, rOrders;
procedure TFData.btnPDFClick(Sender: TObject);
begin
GetReportPDF('');
end;
procedure TFData.FormCreate(Sender: TObject);
begin
......@@ -76,4 +83,30 @@ begin
end;
function TFData.GetReportPDF(OrderID: string): string;
var
rptOrders: TrptOrders; // Local instance
OrderIDList: TStringList;
begin
rptOrders := TrptOrders.Create(nil); // Always create locally
try
// Create a list of hardcoded OrderIDs for testing
OrderIDList := TStringList.Create;
try
OrderIDList.Add('18995');
OrderIDList.Add('18994');
OrderIDList.Add('18993'); // Add more OrderIDs as needed
// Generate the PDF Report with the list of OrderIDs
rptOrders.GenerateSimpleReport(350);
finally
OrderIDList.Free; // Free the TStringList
end;
finally
rptOrders.Free; // Ensure rptOrders is freed
end;
end;
end.
......@@ -209,6 +209,8 @@ type
[HttpGet] function GetOrder(orderInfo: string): TFullOrder;
[HttpGet] function GetCustomers(): TCustomerList;
[HttpGet] function GetCustomer(ID: string): TCustomerItem;
[HttpGet] procedure GenerateReportPDF(searchOptions: string);
function AddUser(userInfo: string): string;
function AddItem(itemInfo: string): string;
......
......@@ -11,8 +11,14 @@ interface
uses
XData.Server.Module,
XData.Service.Common,
KGOrders.Database, Data.DB,
Lookup.Service, System.Hash, System.Classes, System.JSON;
KGOrders.Database, Data.DB, frxClass, frxExportPDF,
Lookup.Service, System.Hash, System.JSON, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, MemDS, DBAccess, Uni,
hyiedefs, hyieutils, iexBitmaps, iesettings, iexLayers, iexRulers,
iexToolbars, iexUserInteractions, imageenio, imageenproc, QuickRpt, QRCtrls,
dbimageen, Vcl.ExtCtrls, ieview, imageenview, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdFTP,
iexProcEffects, frxDBSet, frxExportBaseDialog, frCoreClasses, rOrders, Common.Logging;
type
......@@ -29,6 +35,8 @@ type
function GetCustomer(ID: string): TCustomerItem;
function EditUser(const editOptions: string): string;
function Search(phoneNum: string): TOrderList;
procedure GenerateReportPDF(searchOptions: string);
function BuildOrderQuery(searchOptions: string): string;
function AddUser(userInfo: string): string;
function AddItem(itemInfo: string): string;
function DelUser(username: string): string;
......@@ -44,7 +52,6 @@ type
implementation
uses
System.SysUtils,
System.Generics.Collections,
XData.Sys.Exceptions, uLibrary;
......@@ -156,6 +163,113 @@ begin
end;
procedure TLookupService.GenerateReportPDF(searchOptions: string);
var
SQL: string;
rptOrders: TrptOrders; // Local instance of rptOrders
begin
// Create instance of rptOrders
rptOrders := TrptOrders.Create(nil);
try
// Generate SQL dynamically using the existing GetOrders logic
SQL := BuildOrderQuery(searchOptions);
// Prepare the report dataset
rptOrders.PrepareReport(SQL);
// Generate the PDF report
rptOrders.GeneratePDF;
// Optionally, log success
Logger.log(5, 'PDF Report successfully generated for searchOptions: ' + searchOptions);
finally
rptOrders.Free; // Ensure proper cleanup
end;
end;
function TLookupService.BuildOrderQuery(searchOptions: string): string;
var
params: TStringList;
PageNum, PageSize: integer;
startDate, endDate, filterType, statusType, statusSuffix: string;
statusTableShort, statusTableLong, whereSQL, SQL: string;
begin
params := TStringList.Create;
try
params.StrictDelimiter := true;
params.Delimiter := '&';
params.DelimitedText := searchOptions;
// Parse parameters
PageNum := StrToIntDef(params.Values['pagenumber'], 1);
PageSize := StrToIntDef(params.Values['pagesize'], 50);
startDate := params.Values['startDate'];
endDate := params.Values['endDate'];
filterType := params.Values['filterType'];
statusType := '';
statusSuffix := '';
if filterType <> '' then
begin
statusType := filterType.Split(['_'])[0];
statusSuffix := filterType.Split(['_'])[1];
filterType := statusType + '_' + statusSuffix;
end;
// Determine status table
if statusSuffix = 'DUE' then
begin
statusTableShort := 'oss';
statusTableLong := 'orders_status_schedule';
end
else
begin
statusTableShort := 'os';
statusTableLong := 'orders_status';
end;
// Build the SELECT query with dynamically generated subqueries
SQL := 'SELECT o.ORDER_ID, c.NAME AS COMPANY_NAME, o.JOB_NAME, o.ORDER_DATE, o.ORDER_TYPE, ';
// Add dynamically generated subqueries
SQL := SQL + generateSubQuery(filterType, statusType, 'PROOF');
SQL := SQL + generateSubQuery(filterType, statusType, 'ART');
SQL := SQL + generateSubQuery(filterType, statusType, 'PLATE');
SQL := SQL + generateSubQuery(filterType, statusType, 'MOUNT');
SQL := SQL + generateSubQuery(filterType, statusType, 'SHIP');
// Include additional static fields
SQL := SQL + 'o.PRICE, qb.QB_REF_NUM ';
// FROM clause
SQL := SQL + 'FROM orders o ' +
'JOIN customers c ON o.COMPANY_ID = c.CUSTOMER_ID ' +
'LEFT JOIN qb_sales_orders qb ON qb.ORDER_ID = o.ORDER_ID ';
// WHERE clause
whereSQL := 'WHERE 1=1 ';
if startDate <> '' then
whereSQL := whereSQL + ' AND o.ORDER_DATE >= ' + QuotedStr(startDate);
if endDate <> '' then
whereSQL := whereSQL + ' AND o.ORDER_DATE <= ' + QuotedStr(endDate);
if statusType <> '' then
whereSQL := whereSQL + ' AND ' + statusTableShort + '.ORDER_STATUS = ' + QuotedStr(statusType);
// Add WHERE and ORDER clauses
SQL := SQL + whereSQL +
' ORDER BY o.ORDER_DATE DESC ' +
' LIMIT ' + IntToStr(PageSize) +
' OFFSET ' + IntToStr((PageNum - 1) * PageSize);
Result := SQL;
Logger.log(5, 'Generated SQL in Build order Query: ' + SQL);
finally
params.Free;
end;
end;
function TLookupService.generateSelectSQL(filterType, startDate, endDate: string): string;
begin
......@@ -520,11 +634,9 @@ begin
result.general_special_instructions := ordersDB.UniQuery1.FieldByName('general_special_instructions').AsString
else
//result.specialInstructions := ordersDB.UniQuery1.FieldByName('general_comments').AsString
end;
function TLookupService.GetItems(searchOptions: string): TItemList;
var
params: TStringList;
......@@ -988,6 +1100,8 @@ begin
end;
end;
initialization
RegisterServiceType(TLookupService);
......
unit rOrders;
interface
uses
System.SysUtils, System.Classes, frxClass, frxExportBaseDialog, frxExportPDF,
Data.DB, DBAccess, Uni, UniProvider, MySQLUniProvider, System.IniFiles, Vcl.Forms,
MemDS, frxDBSet, frxTableObject, frCoreClasses, Common.Logging, System.IOUtils;
type
TrptOrders = class(TDataModule)
frxOrders: TfrxReport;
frxPDFExport1: TfrxPDFExport;
ucKG: TUniConnection;
uqOrders: TUniQuery;
frxReportTableObject1: TfrxReportTableObject;
frxDBOrders: TfrxDBDataset;
procedure DataModuleCreate(Sender: TObject);
private
public
procedure GenerateSimpleReport(OrderID: Integer);
procedure PrepareReport(const SQL: string);
procedure GeneratePDF;
end;
var
rptOrders: TrptOrders;
implementation
{%CLASSGROUP 'Vcl.Controls.TControl'}
{$R *.dfm}
procedure TrptOrders.DataModuleCreate(Sender: TObject);
var
iniFile: TIniFile;
begin
// Load database connection settings from INI file
iniFile := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'kgOrdersServer.ini');
try
ucKG.Server := iniFile.ReadString('Database', 'Server', '');
ucKG.Connect;
finally
iniFile.Free;
end;
end;
procedure TrptOrders.GenerateSimpleReport(OrderID: Integer);
begin
try
Logger.Log(5, 'Generating Report for Order ID: ' + OrderID.ToString);
uqOrders.Close;
uqOrders.SQL.Text := 'SELECT ORDER_ID FROM corrugated_plate_orders WHERE ORDER_ID = :OrderID';
uqOrders.ParamByName('OrderID').AsInteger := OrderID;
try
uqOrders.Open;
except
on E: Exception do
begin
Logger.Log(1, 'Error executing query: ' + E.Message);
Exit;
end;
end;
frxOrders.PrepareReport;
frxOrders.ShowReport;
finally
uqOrders.Close;
frxOrders.Clear;
Logger.Log(5, 'Report generation complete for Order ID: ' + OrderID.ToString);
end;
end;
procedure TrptOrders.PrepareReport(const SQL: string);
begin
// Prepare and load data into the query
uqOrders.Close;
uqOrders.SQL.Text := SQL;
uqOrders.Open;
end;
procedure TrptOrders.GeneratePDF;
var
ReportDir, ReportFileName: string;
begin
ReportDir := 'C:\Projects\KGOrders\Reports';
// Define output file
ReportFileName := TPath.Combine(ReportDir, 'OrderReport_' + FormatDateTime('yyyymmdd_hhnnss', Now) + '.pdf');
// Prepare and export the report
frxOrders.PrepareReport;
frxPDFExport1.FileName := ReportFileName;
frxPDFExport1.ShowDialog := False;
frxOrders.Export(frxPDFExport1);
frxOrders.ShowPreparedReport;
Logger.Log(5, 'PDF saved to: ' + ReportFileName);
end;
end.
......@@ -20,7 +20,8 @@ uses
Auth.ServiceImpl in 'Source\Auth.ServiceImpl.pas',
Lookup.ServiceImpl in 'Source\Lookup.ServiceImpl.pas',
App.Server.Module in 'Source\App.Server.Module.pas' {AppServerModule: TDataModule},
Data in 'Source\Data.pas' {FData};
Data in 'Source\Data.pas' {FData},
rOrders in 'Source\rOrders.pas' {rptOrders: TDataModule};
type
TMemoLogAppender = class( TInterfacedObject, ILogAppender )
......
......@@ -164,6 +164,11 @@
<Form>FData</Form>
<FormType>dfm</FormType>
</DCCReference>
<DCCReference Include="Source\rOrders.pas">
<Form>rptOrders</Form>
<FormType>dfm</FormType>
<DesignClass>TDataModule</DesignClass>
</DCCReference>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment