As show in the image wanted to display this in CSV form in mail need usernames from user table and it's total sales order which is in posted sales shipment and also how many sales order is posted each day (for one month back from today)
1)This is my code,not getting the sales order for each day
2)Unable to create CSV and get data as shown in image
codeunit 50129 " Orders packed by packer"
{
procedure shipmentorder()
var
rec_postedsales: Record "Sales Shipment Header";
rec_postedsales2: Record "Sales Shipment Header";
rec_User: Record User;
user: text;
TotalUserOrder: Integer;
postingDate: Date;
begin
rec_postedsales.Reset();
rec_postedsales.SetFilter("User ID", '<>%1', '');
rec_postedsales.SetFilter("Order No.", '<>%1', '');
rec_postedsales.SetRange("Posting Date", Today -31, Today );
TotalUserOrder := rec_postedsales.Count;
if rec_postedsales.FindSet() then
repeat
if postingDate <> rec_postedsales."Posting Date" then begin
rec_postedsales2.SetRange("Posting Date", rec_postedsales."Posting Date")
Message('Total Orders %1 on Posting Date %2', rec_postedsales2.Count, rec_postedsales2."Posting Date");
end;
postingDate := rec_postedsales."Posting Date";
until rec_postedsales.Next() < 1;
InsertIntoTable(rec_postedsales);
until rec_postedsales.Next() < 1;
end;
procedure InsertIntoTable(rec_postedsales: Record "Sales Shipment Header")
var
rec_orderspack: Record "Orders packed by packer";//table
begin
rec_orderspack.Init();
rec_orderspack.No := CreateGuid();
rec_orderspack.Username := rec_postedsales."User ID";
rec_orderspack.Insert();
end;
procedure SendEmail()
var
cdu_EmailMessage: Codeunit "Email Message";
cdu_Email: Codeunit Email;
enum_Alerts: Enum Alerts;
Subject: Text;
Body: Text;
rec_orderspack: Record "Orders packed by packer";//table
begin
Subject := 'This month orders packed by packer';
Body += '<style>table, th, td {border:1px solid #999999;border-collapse: collapse;text-align:left;}th{padding:5px;background:#ccc;}td{padding:5px;}</style>';
Body += '<table border="1">';
Body += '<tr>';
Body += '<th>Username</th>';
Body += '<th>1</th>';//day one is it correct way?
Body += '<th>2</th>'; //day two
Body += '<th>3</th>';
Body += '<th>4</th>';
Body += '<th>5</th>';
Body += '<th>6</th>';
Body += '<th>7</th>';
Body += '<th>8</th>';
Body += '<th>9</th>';
Body += '<th>10</th>';
Body += '</tr>';
Body += '</tr>';
if rec_orderspack.FindSet() then
repeat
Body += '<tr>';
Body += STRSUBSTNO('<td>%1</td>', rec_orderspack.Username);
Body += '</tr>';
until rec_orderspack.Next() = 0;
Body += '</table>';
Body += '<br><br>Kind Regards,<br><br>Business Central';
cdu_EmailMessage.Create(cdu_CommonHelper.EmailSetup(enum_Alerts::" Orders packed by packer"), Subject, Body, true);
if rec_orderspack.Count > 0 then begin
cdu_Email.Send(cdu_EmailMessage);
rec_orderspack.DeleteAll();
end;
end;
}
So can you please help in this code..
I want to get output as shown in image i.e count of sales order which is in post sales shipment of each today (from -31 today)
Please do help in this.
Thankyou