forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPDFFGLabel.php
219 lines (202 loc) · 8.37 KB
/
PDFFGLabel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
include('includes/session.php');
if (isset($_GET['WO'])) {
$SelectedWO = $_GET['WO'];
} elseif (isset($_POST['WO'])){
$SelectedWO = $_POST['WO'];
} else {
unset($SelectedWO);
}
if (isset($_GET['StockID'])) {
$StockID = $_GET['StockID'];
} elseif (isset($_POST['StockID'])){
$StockID = $_POST['StockID'];
} else {
unset($StockID);
}
if (isset($_GET['LabelItem'])) {
$LabelItem = $_GET['LabelItem'];
} elseif (isset($_POST['LabelItem'])){
$LabelItem = $_POST['LabelItem'];
} else {
unset($LabelItem);
}
if (isset($_GET['LabelDesc'])) {
$LabelDesc = $_GET['LabelDesc'];
} elseif (isset($_POST['LabelDesc'])){
$LabelDesc = $_POST['LabelDesc'];
} else {
unset($LabelDesc);
}
if (isset($_GET['LabelLot'])) {
$LabelLot = $_GET['LabelLot'];
} elseif (isset($_POST['LabelLot'])){
$LabelLot = $_POST['LabelLot'];
} else {
unset($LabelLot);
}
if (isset($_GET['NoOfBoxes'])) {
$NoOfBoxes = $_GET['NoOfBoxes'];
} elseif (isset($_POST['NoOfBoxes'])){
$NoOfBoxes = $_POST['NoOfBoxes'];
} else {
unset($NoOfBoxes);
}
if (isset($_GET['LabelsPerBox'])) {
$LabelsPerBox = $_GET['LabelsPerBox'];
} elseif (isset($_POST['LabelsPerBox'])){
$LabelsPerBox = $_POST['LabelsPerBox'];
} else {
unset($LabelsPerBox);
}
if (isset($_GET['QtyPerBox'])) {
$QtyPerBox = $_GET['QtyPerBox'];
} elseif (isset($_POST['QtyPerBox'])){
$QtyPerBox = $_POST['QtyPerBox'];
} else {
unset($QtyPerBox);
}
if (isset($_GET['LeftOverQty'])) {
$LeftOverQty = $_GET['LeftOverQty'];
} elseif (isset($_POST['LeftOverQty'])){
$LeftOverQty = $_POST['LeftOverQty'];
} else {
unset($LeftOverQty);
}
/* If we are previewing the order then we dont want to email it */
if ($SelectedWO == 'Preview') { //WO is set to 'Preview' when just looking at the format of the printed order
$_POST['PrintOrEmail'] = 'Print';
$MakePDFThenDisplayIt = True;
} //$SelectedWO == 'Preview'
if (isset($_POST['DoIt']) AND ($_POST['PrintOrEmail'] == 'Print' OR $ViewingOnly == 1)) {
$MakePDFThenDisplayIt = True;
$MakePDFThenEmailIt = False;
} elseif (isset($_POST['DoIt']) AND $_POST['PrintOrEmail'] == 'Email' AND isset($_POST['EmailTo'])) {
$MakePDFThenEmailIt = True;
$MakePDFThenDisplayIt = False;
}
$FormDesign = simplexml_load_file($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/FGLabel.xml');
// Set the paper size/orintation
$PaperSize = $FormDesign->PaperSize;
$LineHeight=$FormDesign->LineHeight;
include('includes/PDFStarter.php');
$PageNumber=1;
$pdf->addInfo('Title', _('FG Label') );
if ($SelectedWO == 'Preview'){
$MyRow['itemcode'] = str_pad('', 15,'x');
$MyRow['itemdescription'] = str_pad('', 25,'x');
$MyRow['serialno'] = str_pad('', 20,'x');
$MyRow['weight'] = '99999999';
$ControlledRow['1'] = 'lbs';
$ControlledRow['controlled']=1;
$NoOfLabels =1;
} else { //NOT PREVIEW
$i=1;
$NoOfLabels=$NoOfBoxes*$LabelsPerBox;
$BoxNumber=1;
while($i<=$NoOfLabels){
$MyArray[$i]['itemcode']=$LabelItem;
$MyArray[$i]['itemdescription']=$LabelDesc;
$MyArray[$i]['serialno']=$LabelLot;
$MyArray[$i]['weight']=$QtyPerBox;
$MyArray[$i]['box']=$BoxNumber;
if ($i % $LabelsPerBox == 0) {
$BoxNumber+=1;
}
$i++;
}
if ($LeftOverQty>0) {
$j=1;
while($j<=$LabelsPerBox){
$MyArray[$i]['itemcode']=$LabelItem;
$MyArray[$i]['itemdescription']=$LabelDesc;
$MyArray[$i]['serialno']=$LabelLot;
$MyArray[$i]['weight']=$LeftOverQty;
$MyArray[$i]['box']=$BoxNumber;
if ($i % $LabelsPerBox == 0) {
$BoxNumber+=1;
}
$i++;
$j++;
$NoOfLabels++;
}
}
} // get data to print
if ($NoOfLabels >0){
for ($i=1;$i<=$NoOfLabels;$i++) {
if ($SelectedWO!='Preview'){
$MyRow = $MyArray[$i];
//echo $MyRow['itemcode'] ;
$SQL = "SELECT stockmaster.controlled,
stockmaster.units
FROM stockmaster WHERE stockid ='" . $MyRow['itemcode'] . "'";
//echo $SQL;
$CheckControlledResult = DB_query($SQL,'<br />' . _('Could not determine if the item was controlled or not because') . ' ');
$ControlledRow = DB_fetch_row($CheckControlledResult);
//var_dump($ControlledRow);
}
if ($PageNumber>1){
$pdf->newPage();
}
$PageNumber++;
$pdf->addJpegFromFile($_SESSION['LogoFile'] ,$FormDesign->logo->x,$Page_Height-$FormDesign->logo->y,$FormDesign->logo->width,$FormDesign->logo->height);
$pdf->addText($FormDesign->CompanyAddress->Line1->x,$Page_Height - $FormDesign->CompanyAddress->Line1->y, $FormDesign->CompanyAddress->Line1->FontSize, $_SESSION['CompanyRecord']['regoffice1']);
$pdf->addText($FormDesign->CompanyAddress->Line2->x,$Page_Height - $FormDesign->CompanyAddress->Line2->y, $FormDesign->CompanyAddress->Line2->FontSize, $_SESSION['CompanyRecord']['regoffice2']);
$pdf->addText($FormDesign->CompanyAddress->Line3->x,$Page_Height - $FormDesign->CompanyAddress->Line3->y, $FormDesign->CompanyAddress->Line3->FontSize, $_SESSION['CompanyRecord']['regoffice3']);
$pdf->addText($FormDesign->CompanyAddress->phone->x,$Page_Height - $FormDesign->CompanyAddress->phone->y, $FormDesign->CompanyAddress->phone->FontSize, _('Tel'). ': ' . $_SESSION['CompanyRecord']['telephone']);
$pdf->addText($FormDesign->CompanyAddress->www->x,$Page_Height - $FormDesign->CompanyAddress->www->y, $FormDesign->CompanyAddress->www->FontSize, $_SESSION['CompanyRecord']['regoffice4']);
$pdf->Line($FormDesign->LabelLine->startx, $Page_Height - $FormDesign->LabelLine->starty, $FormDesign->LabelLine->endx,$Page_Height - $FormDesign->LabelLine->endy);
$pdf->addText($FormDesign->ItemNbr->x,$Page_Height-$FormDesign->ItemNbr->y,$FormDesign->ItemNbr->FontSize,'Item: ' . $MyRow['itemcode']);
$pdf->addText($FormDesign->ItemDesc->x,$Page_Height-$FormDesign->ItemDesc->y,$FormDesign->ItemDesc->FontSize,'Description: ' . $MyRow['itemdescription']);
$pdf->addText($FormDesign->Weight->x,$Page_Height-$FormDesign->Weight->y,$FormDesign->Weight->FontSize,'Weight' . '(' . $ControlledRow['1'] . '): ' . $MyRow['weight']);
$pdf->addText($FormDesign->Box->x,$Page_Height-$FormDesign->Box->y,$FormDesign->Box->FontSize,'Box' . ': ' . $MyRow['box']);
if ($ControlledRow[0]==1) { /*Then its a controlled item */
$pdf->addText($FormDesign->Lot->x,$Page_Height-$FormDesign->Lot->y,$FormDesign->Lot->FontSize,'Lot: ' . $MyRow['serialno']);
} //controlled item*/
} //end of loop around GRNs to print
$Success = 1; //assume the best and email goes - has to be set to 1 to allow update status
if ($MakePDFThenDisplayIt) {
$pdf->OutputD($_SESSION['DatabaseName'] . '_FGLABEL_' . $SelectedWO . '_' . date('Y-m-d') . '.pdf');
$pdf->__destruct();
} else {
$PdfFileName = $_SESSION['DatabaseName'] . '__FGLABEL_' . $SelectedWO . '_' . date('Y-m-d') . '.pdf';
$pdf->Output($_SESSION['reports_dir'] . '/' . $PdfFileName, 'F');
$pdf->__destruct();
include('includes/htmlMimeMail.php');
$mail = new htmlMimeMail();
$Attachment = $mail->getFile($_SESSION['reports_dir'] . '/' . $PdfFileName);
$mail->setText(_('Please Process this Work order number') . ' ' . $SelectedWO);
$mail->setSubject(_('Work Order Number') . ' ' . $SelectedWO);
$mail->addAttachment($Attachment, $PdfFileName, 'application/pdf');
//since sometime the mail server required to verify the users, so must set this information.
if($_SESSION['SmtpSetting'] == 0){//use the mail service provice by the server.
$mail->setFrom($_SESSION['CompanyRecord']['coyname'] . '<' . $_SESSION['CompanyRecord']['email'] . '>');
$Success = $mail->send(array($_POST['EmailTo']));
}else if($_SESSION['SmtpSetting'] == 1) {
$Success = SendEmailByHTMLMimeMail($mail,array($_POST['EmailTo']));
}else{
prnMsg(_('The SMTP settings are wrong, please ask administrator for help'),'error');
exit;
include('includes/footer.php');
}
if ($Success == 1) {
$Title = _('Email a Work Order');
include('includes/header.php');
echo '<div class="centre"><br /><br /><br />';
prnMsg(_('Work Order') . ' ' . $SelectedWO . ' ' . _('has been emailed to') . ' ' . $_POST['EmailTo'] . ' ' . _('as directed'), 'success');
} else { //email failed
$Title = _('Email a Work Order');
include('includes/header.php');
echo '<div class="centre"><br /><br /><br />';
prnMsg(_('Emailing Work order') . ' ' . $SelectedWO . ' ' . _('to') . ' ' . $_POST['EmailTo'] . ' ' . _('failed'), 'error');
}
}
include('includes/footer.php');
} else { //there were not labels to print
$Title = _('Label Error');
include('includes/header.php');
prnMsg(_('There were no labels to print'),'warn');
echo '<br /><a href="'.$RootPath.'/index.php">' . _('Back to the menu') . '</a>';
include('includes/footer.php');
}
?>