| 39 | | |
| 40 | | if(!isset($_SESSION["userinfo"])){ |
| 41 | | |
| 42 | | //set encoding to latin1 (fpdf doesnt like utf8) |
| 43 | | $sqlEncoding = "latin1"; |
| 44 | | require_once("../../../include/session.php"); |
| 45 | | |
| 46 | | } |
| 47 | | |
| 48 | | if(!class_exists("phpbmsReport")) |
| 49 | | include("report/report_class.php"); |
| 50 | | |
| 51 | | class receiptPDF extends phpbmsReport{ |
| 52 | | |
| 53 | | var $title = "Receipt"; |
| 54 | | var $lineitemBoxHeight = 4.25; |
| 55 | | /** |
| 56 | | * $count |
| 57 | | * @var int The number of invoice records being displayed |
| 58 | | */ |
| 59 | | var $count; |
| 60 | | |
| 61 | | function receiptPDF($db, $orientation='P', $unit='mm', $format='Letter'){ |
| 62 | | |
| 63 | | $this->db = $db; |
| 64 | | |
| 65 | | if(!class_exists("phpbmsPDFReport")) |
| 66 | | include("report/pdfreport_class.php"); |
| 67 | | |
| 68 | | $this->pdf = new phpbmsPDFReport($db, $orientation, $unit, $format); |
| 69 | | |
| 70 | | $this->initialize(); |
| 71 | | |
| 72 | | }//end method |
| 73 | | |
| 74 | | |
| 75 | | function initialize(){ |
| 76 | | //This function will set column headings, sizes and formatting |
| 77 | | |
| 78 | | $pdf = &$this->pdf; |
| 79 | | |
| 80 | | $topinfo = array(); |
| 81 | | $topinfo[] = new pdfColumn("ID", "id", 0.75); |
| 82 | | $topinfo[] = new pdfColumn("Date", "receiptdate", 1, "date"); |
| 83 | | $topinfo[] = new pdfColumn("Processed By", "processedby", 0); |
| 84 | | |
| 85 | | $size = 0; |
| 86 | | foreach($topinfo as $column) |
| 87 | | $size += $column->size; |
| 88 | | |
| 89 | | $topinfo[2]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; |
| 90 | | |
| 91 | | $this->topinfo = $topinfo; |
| 92 | | |
| 93 | | |
| 94 | | $lineitems = array(); |
| 95 | | $lineitems[] = new pdfColumn("Doc Ref", "relatedid", 0.5); |
| 96 | | $lineitems[] = new pdfColumn("Type", "type", 0.75); |
| 97 | | $lineitems[] = new pdfColumn("Doc Date", "itemdate", 0.75, "date"); |
| 98 | | $lineitems[] = new pdfColumn("Due Date", "duedate", 0.75, "date"); |
| 99 | | |
| 100 | | $lineitems[] = new pdfColumn("Doc Amount", "amount", 0, "currency", "R"); |
| 101 | | $lineitems[] = new pdfColumn("Applied", "applied", 0.75, "currency", "R"); |
| 102 | | $lineitems[] = new pdfColumn("Discount", "discount", 0.75, "currency", "R"); |
| 103 | | $lineitems[] = new pdfColumn("Tax Adj", "taxadjustment", 0.75, "currency", "R"); |
| 104 | | |
| 105 | | $size = 0; |
| 106 | | foreach($lineitems as $column) |
| 107 | | $size += $column->size; |
| 108 | | |
| 109 | | $lineitems[4]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; |
| 110 | | |
| 111 | | $this->lineitems = $lineitems; |
| 112 | | |
| 113 | | $totalsinfo = array(); |
| 114 | | $totalsinfo[] = new pdfColumn("Distribution Remaining", "remaining", 0, "currency", "R"); |
| 115 | | $totalsinfo[] = new pdfColumn("Receipt Total", "amount", 0, "currency", "R"); |
| 116 | | |
| 117 | | $this->totalsinfo = $totalsinfo; |
| 118 | | |
| 119 | | }//end method |
| 120 | | |
| 121 | | |
| 122 | | function generate($whereclause = NULL, $sortorder = "receipts.id"){ |
| 123 | | |
| 124 | | $pdf = &$this->pdf; |
| 125 | | |
| 126 | | if($whereclause) |
| 127 | | $this->whereclause = $whereclause; |
| 128 | | elseif(!$this->whereclause) |
| 129 | | $this->whereclause = "receipts.id = -400"; |
| 130 | | |
| 131 | | if($sortorder) |
| 132 | | $this->sortorder = $sortorder; |
| 133 | | elseif(!$this->sortorder) |
| 134 | | $this->sortorder = "receipts.id"; |
| 135 | | |
| 136 | | $paymentFields = ""; |
| 137 | | if(ENCRYPT_PAYMENT_FIELDS){ |
| 138 | | |
| 139 | | $paymentFields = " |
| 140 | | ".$this->db->decrypt("`ccnumber`")." AS `ccnumber`, |
| 141 | | ".$this->db->decrypt("`ccverification`")." AS `ccverification`, |
| 142 | | ".$this->db->decrypt("`ccexpiration`")." AS `ccexpiration`, |
| 143 | | ".$this->db->decrypt("`routingnumber`")." AS `routingnumber`, |
| 144 | | ".$this->db->decrypt("`accountnumber`")." AS `accountnumber`, |
| 145 | | "; |
| 146 | | |
| 147 | | }//end if |
| 148 | | |
| 149 | | $querystatement = " |
| 150 | | SELECT |
| 151 | | receipts.*, |
| 152 | | ".$paymentFields." |
| 153 | | |
| 154 | | clients.firstname, |
| 155 | | clients.lastname, |
| 156 | | clients.company, |
| 157 | | addresses.address1, |
| 158 | | addresses.address2, |
| 159 | | addresses.city, |
| 160 | | addresses.state, |
| 161 | | addresses.postalcode, |
| 162 | | addresses.country, |
| 163 | | clients.homephone, |
| 164 | | clients.workphone, |
| 165 | | clients.email, |
| 166 | | |
| 167 | | paymentmethods.name AS paymentname, |
| 168 | | paymentmethods.type AS paymenttype, |
| 169 | | |
| 170 | | users.firstname AS processorfirst, |
| 171 | | users.lastname AS processorlast |
| 172 | | |
| 173 | | FROM |
| 174 | | receipts INNER JOIN clients ON receipts.clientid = clients.uuid |
| 175 | | INNER JOIN users ON receipts.modifiedby = users.id INNER JOIN |
| 176 | | addresstorecord ON addresstorecord.tabledefid = 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083' AND addresstorecord.primary = 1 |
| 177 | | AND addresstorecord.recordid = clients.uuid INNER JOIN addresses |
| 178 | | ON addresstorecord.addressid = addresses.uuid |
| 179 | | LEFT JOIN paymentmethods ON receipts.paymentmethodid = paymentmethods.uuid"; |
| 180 | | |
| 181 | | $querystatement = $this->assembleSQL($querystatement); |
| 182 | | $queryresult = $this->db->query($querystatement); |
| 183 | | |
| 184 | | |
| 185 | | $this->count = $this->db->numRows($queryresult); |
| 186 | | if($this->count == 0){ |
| 187 | | |
| 188 | | $this->_showNoRecords(); |
| 189 | | exit; |
| 190 | | |
| 191 | | }//end if |
| 192 | | |
| 193 | | $pdf->hasComapnyHeader = true; |
| 194 | | $pdf->SetMargins(); |
| 195 | | |
| 196 | | //iterate through each invoice record |
| 197 | | while($receiptrecord = $this->db->fetchArray($queryresult)){ |
| 198 | | |
| 199 | | $querystatement = " |
| 200 | | SELECT |
| 201 | | SUM(applied) AS thesum |
| 202 | | FROM |
| 203 | | receiptitems |
| 204 | | WHERE |
| 205 | | receiptid ='".$receiptrecord["uuid"]."' |
| 206 | | "; |
| 207 | | |
| 208 | | $sumresult = $this->db->query($querystatement); |
| 209 | | $sumrecord = $this->db->fetchArray($sumresult); |
| 210 | | |
| 211 | | $receiptrecord["remaining"] = $receiptrecord["amount"] - $sumrecord["thesum"]; |
| 212 | | |
| 213 | | $this->page = 0; |
| 214 | | |
| 215 | | $this->receiptrecord = $receiptrecord; |
| 216 | | |
| 217 | | //adds top info |
| 218 | | $top = $this->_addPage(); |
| 219 | | |
| 220 | | $this->_addLineItems($top); |
| 221 | | |
| 222 | | $pdf->SetXY($pdf->leftmargin, $top["y"] + $this->lineitemBoxHeight + 0.125); |
| 223 | | |
| 224 | | //totals |
| 225 | | $this->_addTotals(); |
| 226 | | |
| 227 | | //Print any special/instructions and stuff |
| 228 | | $this->_addNotes(); |
| 229 | | |
| 230 | | }//end while; |
| 231 | | |
| 232 | | |
| 233 | | }//end method |
| 234 | | |
| 235 | | |
| 236 | | function _addPage(){ |
| 237 | | |
| 238 | | $pdf = &$this->pdf; |
| 239 | | |
| 240 | | $pdf->AddPage(); |
| 241 | | $this->page++; |
| 242 | | |
| 243 | | $nextY = $pdf->getY(); |
| 244 | | |
| 245 | | //TITLE |
| 246 | | $titleWidth=2.375; |
| 247 | | $titleHeight=.25; |
| 248 | | $pdf->setStyle("title"); |
| 249 | | $pdf->SetXY(-1*($titleWidth+$pdf->rightmargin), $pdf->topmargin); |
| 250 | | $pdf->Cell($titleWidth, $titleHeight,$this->title, $pdf->borderDebug,1,"R"); |
| 251 | | |
| 252 | | //CLIENT |
| 253 | | $startY = $pdf->GetY() + 0.75; |
| 254 | | |
| 255 | | $boxHeight = 1.75; |
| 256 | | $boxWidth = ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin)/2 -0.0625; |
| 257 | | |
| 258 | | $pdf->setLineWidth(0.02); |
| 259 | | $pdf->Rect($pdf->leftmargin, $startY, $boxWidth, $boxHeight); |
| 260 | | $pdf->setLineWidth(0.01); |
| 261 | | |
| 262 | | $pdf->setStyle("header"); |
| 263 | | $pdf->setY($startY); |
| 264 | | $pdf->Cell($boxWidth, 0.17, "CLIENT", $pdf->borderDebug, 2, "L", 1); |
| 265 | | $pdf->setStyle("normal"); |
| 266 | | |
| 267 | | //Company Name |
| 268 | | $companyDisplay = ""; |
| 269 | | if($this->receiptrecord["company"]){ |
| 270 | | $companyDisplay .= $this->receiptrecord["company"]; |
| 271 | | if($this->receiptrecord["firstname"]) |
| 272 | | $companyDisplay .= " (".$this->receiptrecord["firstname"]." ".$this->receiptrecord["lastname"].")"; |
| 273 | | } else |
| 274 | | $companyDisplay .= $this->receiptrecord["firstname"]." ".$this->receiptrecord["lastname"]; |
| 275 | | |
| 276 | | $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); |
| 277 | | $pdf->SetFont("Arial", "B", 10); |
| 278 | | $pdf->Cell($boxWidth - 0.125, 0.17, $companyDisplay, $pdf->borderDebug, 2, "L"); |
| 279 | | |
| 280 | | $client = $this->_setClientInfo(); |
| 281 | | |
| 282 | | $pdf->SetFont("Arial", "", 10); |
| 283 | | $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); |
| 284 | | $pdf->MultiCell($boxWidth - 0.125,.17,$client, $pdf->borderDebug); |
| 285 | | |
| 286 | | //PAYMENT |
| 287 | | $pdf->setLineWidth(0.02); |
| 288 | | $pdf->Rect($pdf->leftmargin + $boxWidth + 0.125, $startY, $boxWidth, $boxHeight); |
| 289 | | $pdf->setLineWidth(0.01); |
| 290 | | |
| 291 | | $pdf->setStyle("header"); |
| 292 | | $pdf->setXY($pdf->leftmargin + $boxWidth + 0.125, $startY); |
| 293 | | $pdf->Cell($boxWidth, 0.17, "PAYMENT", $pdf->borderDebug, 2, "L", 1); |
| 294 | | $pdf->setStyle("normal"); |
| 295 | | |
| 296 | | if(!$this->receiptrecord["paymentname"]) |
| 297 | | $this->receiptrecord["paymentname"] = "Other"; |
| 298 | | |
| 299 | | $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); |
| 300 | | $pdf->SetFont("Arial", "B", 10); |
| 301 | | $pdf->Cell($boxWidth - 0.125, 0.17, $this->receiptrecord["paymentname"], $pdf->borderDebug, 2, "L"); |
| 302 | | |
| 303 | | |
| 304 | | $paymentInfo = $this->_getPaymentInfo(); |
| 305 | | $pdf->SetFont("Arial", "", 10); |
| 306 | | $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); |
| 307 | | $pdf->MultiCell($boxWidth - 0.125,.17, $paymentInfo, $pdf->borderDebug); |
| 308 | | |
| 309 | | $pdf->setXY($pdf->leftmargin, $startY + $boxHeight + 0.125); |
| 310 | | |
| 311 | | $this->_addTopInfo(); |
| 312 | | |
| 313 | | //line item headings |
| 314 | | $pdf->setStyle("header"); |
| 315 | | $pdf->SetLineWidth(0.02); |
| 316 | | |
| 317 | | $coords["x"] = $pdf->GetX(); |
| 318 | | $coords["y"] = $pdf->GetY(); |
| 319 | | |
| 320 | | foreach($this->lineitems as $column) |
| 321 | | $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); |
| 322 | | |
| 323 | | |
| 324 | | return $coords; |
| 325 | | |
| 326 | | }//end method |
| 327 | | |
| 328 | | |
| 329 | | function _setClientInfo(){ |
| 330 | | |
| 331 | | $client = $this->receiptrecord["address1"]; |
| 332 | | |
| 333 | | if($this->receiptrecord["address2"]) |
| 334 | | $client .= "\n".$this->receiptrecord["address2"]; |
| 335 | | |
| 336 | | $client .="\n".$this->receiptrecord["city"].", ".$this->receiptrecord["state"]." ".$this->receiptrecord["postalcode"]; |
| 337 | | |
| 338 | | if($this->receiptrecord["country"]) |
| 339 | | $client .=" ".$this->receiptrecord["country"]; |
| 340 | | |
| 341 | | $phoneemail = ""; |
| 342 | | if($this->receiptrecord["workphone"] || $this->receiptrecord["homephone"]){ |
| 343 | | |
| 344 | | if($this->receiptrecord["workphone"]) |
| 345 | | $phoneemail = $this->receiptrecord["workphone"]." (W)"; |
| 346 | | else |
| 347 | | $phoneemail = $this->receiptrecord["homephone"]." (H)"; |
| 348 | | |
| 349 | | $phoneemail.="\n"; |
| 350 | | |
| 351 | | }//end if |
| 352 | | |
| 353 | | if($this->receiptrecord["email"]) |
| 354 | | $phoneemail .= $this->receiptrecord["email"]; |
| 355 | | |
| 356 | | if($phoneemail) |
| 357 | | $client .= "\n\n".$phoneemail; |
| 358 | | |
| 359 | | return $client; |
| 360 | | |
| 361 | | }//end method |
| 362 | | |
| 363 | | |
| 364 | | function _getPaymentInfo(){ |
| 365 | | |
| 366 | | $info = ""; |
| 367 | | |
| 368 | | switch($this->receiptrecord["paymenttype"]){ |
| 369 | | |
| 370 | | case "charge": |
| 371 | | |
| 372 | | $info .= $this->receiptrecord["ccnumber"]; |
| 373 | | $info .= "\n Expires: ".$this->receiptrecord["ccexpiration"]; |
| 374 | | if($this->receiptrecord["ccverification"]) |
| 375 | | $info .= "\n Verification/Pin: ".$this->receiptrecord["ccverification"]; |
| 376 | | break; |
| 377 | | |
| 378 | | case "draft": |
| 379 | | |
| 380 | | $info .= $this->receiptrecord["bankname"]; |
| 381 | | $info .= "\n Check No: ".$this->receiptrecord["checkno"]; |
| 382 | | |
| 383 | | if($this->receiptrecord["accountnumber"] || $this->receiptrecord["routingnumber"]) |
| 384 | | $info .= "\n"; |
| 385 | | |
| 386 | | if($this->receiptrecord["accountnumber"]) |
| 387 | | $info .="\n".$this->receiptrecord["accountnumber"]; |
| 388 | | |
| 389 | | if($this->receiptrecord["routingnumber"]) |
| 390 | | $info .="\n".$this->receiptrecord["routingnumber"]; |
| 391 | | |
| 392 | | break; |
| 393 | | |
| 394 | | default: |
| 395 | | |
| 396 | | if(!$this->receiptrecord["paymentmethodid"]) |
| 397 | | $info .= $this->receiptrecord["paymentother"]; |
| 398 | | |
| 399 | | }//endswitch |
| 400 | | |
| 401 | | if($this->receiptrecord["transactionid"]) |
| 402 | | $info .= "\nTransaction ID: ".$this->receiptrecord["transactionid"]; |
| 403 | | |
| 404 | | return $info; |
| 405 | | |
| 406 | | }//end method |
| 407 | | |
| 408 | | |
| 409 | | function _addTopInfo(){ |
| 410 | | |
| 411 | | $pdf = &$this->pdf; |
| 412 | | |
| 413 | | $pdf->setStyle("header"); |
| 414 | | $pdf->SetLineWidth(0.02); |
| 415 | | |
| 416 | | foreach($this->topinfo as $column) |
| 417 | | $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); |
| 418 | | |
| 419 | | $pdf->Rect($pdf->leftmargin, $pdf->GetY(), ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin), 0.39); |
| 420 | | |
| 421 | | $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + .2); |
| 422 | | |
| 423 | | |
| 424 | | $this->receiptrecord["processedby"] = $this->receiptrecord["processorfirst"]." ".$this->receiptrecord["processorlast"]; |
| 425 | | $pdf->setStyle("normal"); |
| 426 | | |
| 427 | | foreach($this->topinfo as $column){ |
| 428 | | |
| 429 | | if($column->format != "") |
| 430 | | $value = formatVariable($this->receiptrecord[$column->fieldname], $column->format); |
| 431 | | else |
| 432 | | $value = $this->receiptrecord[$column->fieldname]; |
| 433 | | |
| 434 | | $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); |
| 435 | | |
| 436 | | }//end foreach |
| 437 | | |
| 438 | | $pdf->SetY($pdf->GetY() + 0.18 + 0.125); |
| 439 | | |
| 440 | | }//end method |
| 441 | | |
| 442 | | |
| 443 | | function _addLineItems($coords){ |
| 444 | | |
| 445 | | $pdf = &$this->pdf; |
| 446 | | |
| 447 | | $lineitemresult = $this->_getLineItems(); |
| 448 | | |
| 449 | | $pdf->setStyle("normal"); |
| 450 | | |
| 451 | | $pdf->SetY($pdf->GetY() + 0.18 + 0.0625); |
| 452 | | |
| 453 | | while($line = $this->db->fetchArray($lineitemresult)){ |
| 454 | | |
| 455 | | if($pdf->GetY() + 0.17*3 > $coords["y"] + $this->lineitemBoxHeight){ |
| 456 | | |
| 457 | | $pdf->SetLineWidth(0.02); |
| 458 | | $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); |
| 459 | | $pdf->SetLineWidth(0.01); |
| 460 | | |
| 461 | | $this->_addPage(); |
| 462 | | |
| 463 | | }//end if |
| 464 | | |
| 465 | | if($line["type"] == "invoice"){ |
| 466 | | |
| 467 | | $tempDate = stringToDate($line["itemdate"], "SQL"); |
| 468 | | $line["duedate"] = dateToString( strtotime(TERM1_DAYS." days", $tempDate), "SQL" ); |
| 469 | | |
| 470 | | } else |
| 471 | | $line["duedate"] = ""; |
| 472 | | |
| 473 | | if($line["type"] == "deposit" && $line["relatedid"] == $this->receiptrecord["id"]){ |
| 474 | | $line["relatedid"] = ""; |
| 475 | | $line["amount"] = 0; |
| 476 | | $line["aritemid"] = 0; |
| 477 | | } |
| 478 | | |
| 479 | | if($this->receiptrecord["posted"]) |
| 480 | | $line["docdue"] = $line["amount"] - $line["paid"]; |
| 481 | | elseif($line["relatedid"]) |
| 482 | | $line["docdue"] = $line["amount"] - $line["paid"] - $line["applied"] - $line["discount"] - $line["taxadjustment"]; |
| 483 | | else |
| 484 | | $line["docDue"] = 0; |
| 485 | | |
| 486 | | |
| 487 | | foreach($this->lineitems as $column){ |
| 488 | | |
| 489 | | $ln = 0; |
| 490 | | |
| 491 | | |
| 492 | | switch($column->fieldname){ |
| 493 | | |
| 494 | | case "parts": |
| 495 | | $pdf->SetFont("Arial", "B", 8); |
| 496 | | $pdf->Write(0.17, $line["partname"]); |
| 497 | | $pdf->setStyle("normal"); |
| 498 | | $pdf->SetX($pdf->leftmargin + $column->size); |
| 499 | | break; |
| 500 | | |
| 501 | | default: |
| 502 | | if($column->format != "") |
| 503 | | $value = formatVariable($line[$column->fieldname], $column->format); |
| 504 | | else |
| 505 | | $value = $line[$column->fieldname]; |
| 506 | | |
| 507 | | if($value == "·") |
| 508 | | $value = " "; |
| 509 | | |
| 510 | | if($column->fieldname == $this->lineitems[count($this->lineitems)-1]->fieldname) |
| 511 | | $ln = 2; |
| 512 | | |
| 513 | | $pdf->Cell($column->size, 0.17, $value, $pdf->borderDebug, $ln, $column->align); |
| 514 | | break; |
| 515 | | |
| 516 | | }//end switch |
| 517 | | |
| 518 | | }//end foreach |
| 519 | | |
| 520 | | $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); |
| 521 | | $pdf->SetLineWidth(0.01); |
| 522 | | $pdf->SetDrawColor(180,180,180); |
| 523 | | $pdf->Line($pdf->leftmargin, $pdf->GetY(), $pdf->paperwidth - $pdf->rightmargin, $pdf->GetY()); |
| 524 | | $pdf->SetDrawColor(0,0,0); |
| 525 | | $pdf->SetLineWidth(0.02); |
| 526 | | $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); |
| 527 | | |
| 528 | | }//end while |
| 529 | | |
| 530 | | $pdf->SetLineWidth(0.02); |
| 531 | | $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); |
| 532 | | |
| 533 | | }//end method |
| 534 | | |
| 535 | | |
| 536 | | function _getLineItems(){ |
| 537 | | |
| 538 | | $querystatement = " |
| 539 | | SELECT |
| 540 | | receiptitems.aritemid, |
| 541 | | receiptitems.applied, |
| 542 | | receiptitems.discount, |
| 543 | | receiptitems.taxadjustment, |
| 544 | | aritems.type, |
| 545 | | IF(`invoices`.`id`,`invoices`.`id`,`receipts`.`id`) AS `relatedid`, |
| 546 | | aritems.itemdate, |
| 547 | | aritems.amount, |
| 548 | | aritems.paid |
| 549 | | FROM |
| 550 | | ((receiptitems INNER JOIN aritems ON receiptitems.aritemid = aritems.uuid)LEFT JOIN `invoices` ON `aritems`.`relatedid` = `invoices`.`uuid`) LEFT JOIN `receipts` ON `aritems`.`relatedid` = `receipts`.`uuid` |
| 551 | | WHERE |
| 552 | | receiptitems.receiptid = '".mysql_real_escape_string($this->receiptrecord["uuid"])."' |
| 553 | | ORDER BY |
| 554 | | aritems.type, |
| 555 | | aritems.itemdate"; |
| 556 | | |
| 557 | | return $this->db->query($querystatement); |
| 558 | | |
| 559 | | }//end method |
| 560 | | |
| 561 | | |
| 562 | | function _addNotes(){ |
| 563 | | |
| 564 | | $pdf = &$this->pdf; |
| 565 | | |
| 566 | | $height = 1; |
| 567 | | $nextPos = $pdf->GetY() + $height + 0.125; |
| 568 | | |
| 569 | | $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); |
| 570 | | $pdf->setStyle("header"); |
| 571 | | $pdf->Cell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, 0.18, "Notes", 1, 2, "L", 1); |
| 572 | | |
| 573 | | $pdf->setStyle("normal"); |
| 574 | | $pdf->SetXY($pdf->GetX() + .06125, $pdf->GetY() + .06125); |
| 575 | | $pdf->MultiCell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - 0.125, 0.18, $this->receiptrecord["memo"]); |
| 576 | | |
| 577 | | $pdf->SetXY($pdf->leftmargin, $nextPos); |
| 578 | | |
| 579 | | }//end method |
| 580 | | |
| 581 | | |
| 582 | | function _addTotals(){ |
| 583 | | |
| 584 | | $pdf = &$this->pdf; |
| 585 | | |
| 586 | | $size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin; |
| 587 | | |
| 588 | | $tempTotalsinfo = $this->totalsinfo; |
| 589 | | |
| 590 | | if($this->receiptrecord["remaining"]){ |
| 591 | | |
| 592 | | $this->totalsinfo[1]->size = 1; |
| 593 | | $size -= 1; |
| 594 | | |
| 595 | | } else |
| 596 | | array_shift($this->totalsinfo); |
| 597 | | |
| 598 | | $this->totalsinfo[0]->size = $size; |
| 599 | | |
| 600 | | $height = .5; |
| 601 | | $nextPos = $pdf->GetY() + $height + 0.125; |
| 602 | | |
| 603 | | $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); |
| 604 | | |
| 605 | | $pdf->setStyle("header"); |
| 606 | | |
| 607 | | foreach($this->totalsinfo as $column) |
| 608 | | $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); |
| 609 | | |
| 610 | | $pdf->setStyle("normal"); |
| 611 | | $pdf->SetFont("Arial", "B", 10); |
| 612 | | $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.18 + 0.0625); |
| 613 | | |
| 614 | | foreach($this->totalsinfo as $column){ |
| 615 | | |
| 616 | | if($column->format != "") |
| 617 | | $value = formatVariable($this->receiptrecord[$column->fieldname], $column->format); |
| 618 | | else |
| 619 | | $value = $this->receiptrecord[$column->fieldname]; |
| 620 | | |
| 621 | | $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); |
| 622 | | |
| 623 | | }//end foreach |
| 624 | | |
| 625 | | if(isset($this->totalsinfo[1])) |
| 626 | | $this->totalsinfo[1]->size = 0; |
| 627 | | |
| 628 | | $pdf->SetXY($pdf->leftmargin, $nextPos); |
| 629 | | |
| 630 | | $this->totalsinfo = $tempTotalsinfo; |
| 631 | | |
| 632 | | }//end method |
| 633 | | |
| 634 | | |
| 635 | | |
| 636 | | function output($destination = "screen" , $userinfo = NULL){ |
| 637 | | |
| 638 | | switch($destination){ |
| 639 | | |
| 640 | | case "screen": |
| 641 | | $userinfo = cleanFilename((string)$userinfo); |
| 642 | | $this->pdf->Output($userinfo, 'D'); |
| 643 | | break; |
| 644 | | |
| 645 | | case "email": |
| 646 | | |
| 647 | | if(!$userinfo) |
| 648 | | $userinfo = $_SESSION["userinfo"]; |
| 649 | | |
| 650 | | if(!$userinfo["email"] || !$this->receiptrecord["email"]) |
| 651 | | return false; |
| 652 | | |
| 653 | | $pdf = $this->pdf->Output(NULL, "S"); |
| 654 | | |
| 655 | | $to = $this->receiptrecord["email"]; |
| 656 | | $from = $userinfo["email"]; |
| 657 | | $subject = "Your ".$this->title." from ".COMPANY_NAME; |
| 658 | | $message = "Attached is your ".$this->title." from ".COMPANY_NAME."\n\n" . |
| 659 | | "The attachment requires Adobe Acrobat Reader to view. \n If you do not " . |
| 660 | | "have Acrobat Reader, you can download it at http://www.adobe.com \n\n" . |
| 661 | | COMPANY_NAME."\n". |
| 662 | | COMPANY_ADDRESS."\n".COMPANY_CSZ."\n".COMPANY_PHONE; |
| 663 | | |
| 664 | | $headers = "From: $from"; |
| 665 | | |
| 666 | | $semi_rand = md5( time() ); |
| 667 | | $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; |
| 668 | | |
| 669 | | $headers .= "\nMIME-Version: 1.0\n" . |
| 670 | | "Content-Type: multipart/mixed;\n" . |
| 671 | | " boundary=\"{$mime_boundary}\""; |
| 672 | | |
| 673 | | $message = "This is a multi-part message in MIME format.\n\n" . |
| 674 | | "--{$mime_boundary}\n" . |
| 675 | | "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . |
| 676 | | "Content-Transfer-Encoding: 7bit\n\n" . |
| 677 | | $message . "\n\n"; |
| 678 | | |
| 679 | | $pdf = chunk_split( base64_encode( $pdf ) ); |
| 680 | | |
| 681 | | $message .= "--{$mime_boundary}\n" . |
| 682 | | "Content-Type: {application/pdf};\n" . |
| 683 | | " name=\"".$this->title.$this->receiptrecord["id"]."\"\n" . |
| 684 | | "Content-Disposition: attachment;\n" . |
| 685 | | " filename=\"".$this->title.$this->receiptrecord["id"].".pdf\"\n" . |
| 686 | | "Content-Transfer-Encoding: base64\n\n" . |
| 687 | | $pdf . "\n\n" . |
| 688 | | "--{$mime_boundary}--\n"; |
| 689 | | |
| 690 | | return @ mail($to, $subject, $message, $headers); |
| 691 | | |
| 692 | | break; |
| 693 | | |
| 694 | | }//endswitch |
| 695 | | |
| 696 | | }//end method |
| 697 | | |
| 698 | | }//end class |
| 699 | | |
| 700 | | |
| 701 | | //PROCESSING |
| 702 | | //============================================================================= |
| | 39 | if(!class_exists("phpbmsReport")) |
| | 40 | include("../../../report/report_class.php"); |
| | 41 | |
| | 42 | class receiptPDF extends phpbmsReport{ |
| | 43 | |
| | 44 | var $lineitemBoxHeight = 4.25; |
| | 45 | |
| | 46 | /** |
| | 47 | * $count |
| | 48 | * @var int The number of invoice records being displayed |
| | 49 | */ |
| | 50 | var $count; |
| | 51 | |
| | 52 | |
| | 53 | function receiptPDF($db, $reportUUID, $tabledefUUID, $orientation='P', $unit='mm', $format='Letter'){ |
| | 54 | |
| | 55 | parent::phpbmsReport($db, $reportUUID, $tabledefUUID); |
| | 56 | |
| | 57 | if(!class_exists("phpbmsPDFReport")) |
| | 58 | include("report/pdfreport_class.php"); |
| | 59 | |
| | 60 | $this->pdf = new phpbmsPDFReport($db, $orientation, $unit, $format); |
| | 61 | |
| | 62 | $this->checkForDefaultSettings(); |
| | 63 | |
| | 64 | $this->initialize(); |
| | 65 | |
| | 66 | $this->pdf->borderDebug = $this->settings["borderDebug"]; |
| | 67 | |
| | 68 | }//end method |
| | 69 | |
| | 70 | |
| | 71 | /** |
| | 72 | * function checkForDefaultSettings |
| | 73 | * |
| | 74 | * Checks to make sure loaded report Settings exist and are correct |
| | 75 | */ |
| | 76 | function checkForDefaultSettings(){ |
| | 77 | |
| | 78 | if(!isset($this->settings["reportTitle"])) |
| | 79 | $this->settings["reportTitle"] = "Receipt"; |
| | 80 | |
| | 81 | if(!isset($this->settings["borderDebug"])) |
| | 82 | $this->settings["borderDebug"] = 0; |
| | 83 | |
| | 84 | }//end function checkForDefaultSettings |
| | 85 | |
| | 86 | |
| | 87 | /** |
| | 88 | * function initialize |
| | 89 | * |
| | 90 | * This function sets column headings sizes, and formatting |
| | 91 | */ |
| | 92 | function initialize(){ |
| | 93 | |
| | 94 | $pdf = &$this->pdf; |
| | 95 | |
| | 96 | $topinfo = array(); |
| | 97 | $topinfo[] = new pdfColumn("ID", "id", 0.75); |
| | 98 | $topinfo[] = new pdfColumn("Date", "receiptdate", 1, "date"); |
| | 99 | $topinfo[] = new pdfColumn("Processed By", "processedby", 0); |
| | 100 | |
| | 101 | $size = 0; |
| | 102 | foreach($topinfo as $column) |
| | 103 | $size += $column->size; |
| | 104 | |
| | 105 | $topinfo[2]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; |
| | 106 | |
| | 107 | $this->topinfo = $topinfo; |
| | 108 | |
| | 109 | |
| | 110 | $lineitems = array(); |
| | 111 | $lineitems[] = new pdfColumn("Doc Ref", "relatedid", 0.5); |
| | 112 | $lineitems[] = new pdfColumn("Type", "type", 0.75); |
| | 113 | $lineitems[] = new pdfColumn("Doc Date", "itemdate", 0.75, "date"); |
| | 114 | $lineitems[] = new pdfColumn("Due Date", "duedate", 0.75, "date"); |
| | 115 | |
| | 116 | $lineitems[] = new pdfColumn("Doc Amount", "amount", 0, "currency", "R"); |
| | 117 | $lineitems[] = new pdfColumn("Applied", "applied", 0.75, "currency", "R"); |
| | 118 | $lineitems[] = new pdfColumn("Discount", "discount", 0.75, "currency", "R"); |
| | 119 | $lineitems[] = new pdfColumn("Tax Adj", "taxadjustment", 0.75, "currency", "R"); |
| | 120 | |
| | 121 | $size = 0; |
| | 122 | foreach($lineitems as $column) |
| | 123 | $size += $column->size; |
| | 124 | |
| | 125 | $lineitems[4]->size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - $size; |
| | 126 | |
| | 127 | $this->lineitems = $lineitems; |
| | 128 | |
| | 129 | $totalsinfo = array(); |
| | 130 | $totalsinfo[] = new pdfColumn("Distribution Remaining", "remaining", 0, "currency", "R"); |
| | 131 | $totalsinfo[] = new pdfColumn("Receipt Total", "amount", 0, "currency", "R"); |
| | 132 | |
| | 133 | $this->totalsinfo = $totalsinfo; |
| | 134 | |
| | 135 | }//end method |
| | 136 | |
| | 137 | |
| | 138 | function generate($whereclause = NULL, $sortorder = "receipts.id"){ |
| | 139 | |
| | 140 | $pdf = &$this->pdf; |
| | 141 | |
| | 142 | if($whereclause) |
| | 143 | $this->whereClause= $whereclause; |
| | 144 | elseif(!$this->whereClause) |
| | 145 | $this->whereClause = "receipts.id = -400"; |
| | 146 | |
| | 147 | if($sortorder) |
| | 148 | $this->sortOrder = $sortorder; |
| | 149 | elseif(!$this->sortOrder) |
| | 150 | $this->sortOrder = "receipts.id"; |
| | 151 | |
| | 152 | $paymentFields = ""; |
| | 153 | if(ENCRYPT_PAYMENT_FIELDS){ |
| | 154 | |
| | 155 | $paymentFields = " |
| | 156 | ".$this->db->decrypt("`ccnumber`")." AS `ccnumber`, |
| | 157 | ".$this->db->decrypt("`ccverification`")." AS `ccverification`, |
| | 158 | ".$this->db->decrypt("`ccexpiration`")." AS `ccexpiration`, |
| | 159 | ".$this->db->decrypt("`routingnumber`")." AS `routingnumber`, |
| | 160 | ".$this->db->decrypt("`accountnumber`")." AS `accountnumber`, |
| | 161 | "; |
| | 162 | |
| | 163 | }//end if |
| | 164 | |
| | 165 | $querystatement = " |
| | 166 | SELECT |
| | 167 | receipts.*, |
| | 168 | ".$paymentFields." |
| | 169 | |
| | 170 | clients.firstname, |
| | 171 | clients.lastname, |
| | 172 | clients.company, |
| | 173 | addresses.address1, |
| | 174 | addresses.address2, |
| | 175 | addresses.city, |
| | 176 | addresses.state, |
| | 177 | addresses.postalcode, |
| | 178 | addresses.country, |
| | 179 | clients.homephone, |
| | 180 | clients.workphone, |
| | 181 | clients.email, |
| | 182 | |
| | 183 | paymentmethods.name AS paymentname, |
| | 184 | paymentmethods.type AS paymenttype, |
| | 185 | |
| | 186 | users.firstname AS processorfirst, |
| | 187 | users.lastname AS processorlast |
| | 188 | |
| | 189 | FROM |
| | 190 | receipts INNER JOIN clients ON receipts.clientid = clients.uuid |
| | 191 | INNER JOIN users ON receipts.modifiedby = users.id INNER JOIN |
| | 192 | addresstorecord ON addresstorecord.tabledefid = 'tbld:6d290174-8b73-e199-fe6c-bcf3d4b61083' AND addresstorecord.primary = 1 |
| | 193 | AND addresstorecord.recordid = clients.uuid INNER JOIN addresses |
| | 194 | ON addresstorecord.addressid = addresses.uuid |
| | 195 | LEFT JOIN paymentmethods ON receipts.paymentmethodid = paymentmethods.uuid"; |
| | 196 | |
| | 197 | $querystatement = $this->assembleSQL($querystatement); |
| | 198 | $queryresult = $this->db->query($querystatement); |
| | 199 | |
| | 200 | |
| | 201 | $this->count = $this->db->numRows($queryresult); |
| | 202 | if($this->count == 0){ |
| | 203 | |
| | 204 | $this->showNoRecords(); |
| | 205 | exit; |
| | 206 | |
| | 207 | }//end if |
| | 208 | |
| | 209 | $pdf->logoInHeader = true; |
| | 210 | $pdf->companyInfoInHeader = true; |
| | 211 | $pdf->SetMargins(); |
| | 212 | |
| | 213 | //iterate through each invoice record |
| | 214 | while($receiptrecord = $this->db->fetchArray($queryresult)){ |
| | 215 | |
| | 216 | $querystatement = " |
| | 217 | SELECT |
| | 218 | SUM(applied) AS thesum |
| | 219 | FROM |
| | 220 | receiptitems |
| | 221 | WHERE |
| | 222 | receiptid ='".$receiptrecord["uuid"]."' |
| | 223 | "; |
| | 224 | |
| | 225 | $sumresult = $this->db->query($querystatement); |
| | 226 | $sumrecord = $this->db->fetchArray($sumresult); |
| | 227 | |
| | 228 | $receiptrecord["remaining"] = $receiptrecord["amount"] - $sumrecord["thesum"]; |
| | 229 | |
| | 230 | $this->page = 0; |
| | 231 | |
| | 232 | $this->receiptrecord = $receiptrecord; |
| | 233 | |
| | 234 | //adds top info |
| | 235 | $top = $this->_addPage(); |
| | 236 | |
| | 237 | $this->_addLineItems($top); |
| | 238 | |
| | 239 | $pdf->SetXY($pdf->leftmargin, $top["y"] + $this->lineitemBoxHeight + 0.125); |
| | 240 | |
| | 241 | //totals |
| | 242 | $this->_addTotals(); |
| | 243 | |
| | 244 | //Print any special/instructions and stuff |
| | 245 | $this->_addNotes(); |
| | 246 | |
| | 247 | $this->receiptrecord = $receiptrecord; |
| | 248 | |
| | 249 | }//end while; |
| | 250 | |
| | 251 | |
| | 252 | }//end method |
| | 253 | |
| | 254 | |
| | 255 | function _addPage(){ |
| | 256 | |
| | 257 | $pdf = &$this->pdf; |
| | 258 | |
| | 259 | $pdf->AddPage(); |
| | 260 | $this->page++; |
| | 261 | |
| | 262 | $nextY = $pdf->getY(); |
| | 263 | |
| | 264 | //TITLE |
| | 265 | $titleWidth=2.375; |
| | 266 | $titleHeight=.25; |
| | 267 | $pdf->setStyle("title"); |
| | 268 | $pdf->SetXY(-1*($titleWidth+$pdf->rightmargin), $pdf->topmargin); |
| | 269 | $pdf->Cell($titleWidth, $titleHeight, $this->settings["reportTitle"], $pdf->borderDebug,1,"R"); |
| | 270 | |
| | 271 | //CLIENT |
| | 272 | $startY = $pdf->GetY() + 0.75; |
| | 273 | |
| | 274 | $boxHeight = 1.75; |
| | 275 | $boxWidth = ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin)/2 -0.0625; |
| | 276 | |
| | 277 | $pdf->setLineWidth(0.02); |
| | 278 | $pdf->Rect($pdf->leftmargin, $startY, $boxWidth, $boxHeight); |
| | 279 | $pdf->setLineWidth(0.01); |
| | 280 | |
| | 281 | $pdf->setStyle("header"); |
| | 282 | $pdf->setY($startY); |
| | 283 | $pdf->Cell($boxWidth, 0.17, "CLIENT", $pdf->borderDebug, 2, "L", 1); |
| | 284 | $pdf->setStyle("normal"); |
| | 285 | |
| | 286 | //Company Name |
| | 287 | $companyDisplay = ""; |
| | 288 | if($this->receiptrecord["company"]){ |
| | 289 | $companyDisplay .= $this->receiptrecord["company"]; |
| | 290 | if($this->receiptrecord["firstname"]) |
| | 291 | $companyDisplay .= " (".$this->receiptrecord["firstname"]." ".$this->receiptrecord["lastname"].")"; |
| | 292 | } else |
| | 293 | $companyDisplay .= $this->receiptrecord["firstname"]." ".$this->receiptrecord["lastname"]; |
| | 294 | |
| | 295 | $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); |
| | 296 | $pdf->SetFont("Arial", "B", 10); |
| | 297 | $pdf->Cell($boxWidth - 0.125, 0.17, $companyDisplay, $pdf->borderDebug, 2, "L"); |
| | 298 | |
| | 299 | $client = $this->_setClientInfo(); |
| | 300 | |
| | 301 | $pdf->SetFont("Arial", "", 10); |
| | 302 | $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); |
| | 303 | $pdf->MultiCell($boxWidth - 0.125,.17,$client, $pdf->borderDebug); |
| | 304 | |
| | 305 | //PAYMENT |
| | 306 | $pdf->setLineWidth(0.02); |
| | 307 | $pdf->Rect($pdf->leftmargin + $boxWidth + 0.125, $startY, $boxWidth, $boxHeight); |
| | 308 | $pdf->setLineWidth(0.01); |
| | 309 | |
| | 310 | $pdf->setStyle("header"); |
| | 311 | $pdf->setXY($pdf->leftmargin + $boxWidth + 0.125, $startY); |
| | 312 | $pdf->Cell($boxWidth, 0.17, "PAYMENT", $pdf->borderDebug, 2, "L", 1); |
| | 313 | $pdf->setStyle("normal"); |
| | 314 | |
| | 315 | if(!$this->receiptrecord["paymentname"]) |
| | 316 | $this->receiptrecord["paymentname"] = "Other"; |
| | 317 | |
| | 318 | $pdf->SetXY($pdf->GetX() + 0.0625, $pdf->GetY() + 0.0625); |
| | 319 | $pdf->SetFont("Arial", "B", 10); |
| | 320 | $pdf->Cell($boxWidth - 0.125, 0.17, $this->receiptrecord["paymentname"], $pdf->borderDebug, 2, "L"); |
| | 321 | |
| | 322 | |
| | 323 | $paymentInfo = $this->_getPaymentInfo(); |
| | 324 | $pdf->SetFont("Arial", "", 10); |
| | 325 | $pdf->setXY($pdf->GetX(), $pdf->GetY() + 0.0625); |
| | 326 | $pdf->MultiCell($boxWidth - 0.125,.17, $paymentInfo, $pdf->borderDebug); |
| | 327 | |
| | 328 | $pdf->setXY($pdf->leftmargin, $startY + $boxHeight + 0.125); |
| | 329 | |
| | 330 | $this->_addTopInfo(); |
| | 331 | |
| | 332 | //line item headings |
| | 333 | $pdf->setStyle("header"); |
| | 334 | $pdf->SetLineWidth(0.02); |
| | 335 | |
| | 336 | $coords["x"] = $pdf->GetX(); |
| | 337 | $coords["y"] = $pdf->GetY(); |
| | 338 | |
| | 339 | foreach($this->lineitems as $column) |
| | 340 | $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); |
| | 341 | |
| | 342 | |
| | 343 | return $coords; |
| | 344 | |
| | 345 | }//end method |
| | 346 | |
| | 347 | |
| | 348 | function _setClientInfo(){ |
| | 349 | |
| | 350 | $client = $this->receiptrecord["address1"]; |
| | 351 | |
| | 352 | if($this->receiptrecord["address2"]) |
| | 353 | $client .= "\n".$this->receiptrecord["address2"]; |
| | 354 | |
| | 355 | $client .="\n".$this->receiptrecord["city"].", ".$this->receiptrecord["state"]." ".$this->receiptrecord["postalcode"]; |
| | 356 | |
| | 357 | if($this->receiptrecord["country"]) |
| | 358 | $client .=" ".$this->receiptrecord["country"]; |
| | 359 | |
| | 360 | $phoneemail = ""; |
| | 361 | if($this->receiptrecord["workphone"] || $this->receiptrecord["homephone"]){ |
| | 362 | |
| | 363 | if($this->receiptrecord["workphone"]) |
| | 364 | $phoneemail = $this->receiptrecord["workphone"]." (W)"; |
| | 365 | else |
| | 366 | $phoneemail = $this->receiptrecord["homephone"]." (H)"; |
| | 367 | |
| | 368 | $phoneemail.="\n"; |
| | 369 | |
| | 370 | }//end if |
| | 371 | |
| | 372 | if($this->receiptrecord["email"]) |
| | 373 | $phoneemail .= $this->receiptrecord["email"]; |
| | 374 | |
| | 375 | if($phoneemail) |
| | 376 | $client .= "\n\n".$phoneemail; |
| | 377 | |
| | 378 | return $client; |
| | 379 | |
| | 380 | }//end method |
| | 381 | |
| | 382 | |
| | 383 | function _getPaymentInfo(){ |
| | 384 | |
| | 385 | $info = ""; |
| | 386 | |
| | 387 | switch($this->receiptrecord["paymenttype"]){ |
| | 388 | |
| | 389 | case "charge": |
| | 390 | |
| | 391 | $info .= $this->receiptrecord["ccnumber"]; |
| | 392 | $info .= "\n Expires: ".$this->receiptrecord["ccexpiration"]; |
| | 393 | if($this->receiptrecord["ccverification"]) |
| | 394 | $info .= "\n Verification/Pin: ".$this->receiptrecord["ccverification"]; |
| | 395 | break; |
| | 396 | |
| | 397 | case "draft": |
| | 398 | |
| | 399 | $info .= $this->receiptrecord["bankname"]; |
| | 400 | $info .= "\n Check No: ".$this->receiptrecord["checkno"]; |
| | 401 | |
| | 402 | if($this->receiptrecord["accountnumber"] || $this->receiptrecord["routingnumber"]) |
| | 403 | $info .= "\n"; |
| | 404 | |
| | 405 | if($this->receiptrecord["accountnumber"]) |
| | 406 | $info .="\n".$this->receiptrecord["accountnumber"]; |
| | 407 | |
| | 408 | if($this->receiptrecord["routingnumber"]) |
| | 409 | $info .="\n".$this->receiptrecord["routingnumber"]; |
| | 410 | |
| | 411 | break; |
| | 412 | |
| | 413 | default: |
| | 414 | |
| | 415 | if(!$this->receiptrecord["paymentmethodid"]) |
| | 416 | $info .= $this->receiptrecord["paymentother"]; |
| | 417 | |
| | 418 | }//endswitch |
| | 419 | |
| | 420 | if($this->receiptrecord["transactionid"]) |
| | 421 | $info .= "\nTransaction ID: ".$this->receiptrecord["transactionid"]; |
| | 422 | |
| | 423 | return $info; |
| | 424 | |
| | 425 | }//end method |
| | 426 | |
| | 427 | |
| | 428 | function _addTopInfo(){ |
| | 429 | |
| | 430 | $pdf = &$this->pdf; |
| | 431 | |
| | 432 | $pdf->setStyle("header"); |
| | 433 | $pdf->SetLineWidth(0.02); |
| | 434 | |
| | 435 | foreach($this->topinfo as $column) |
| | 436 | $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); |
| | 437 | |
| | 438 | $pdf->Rect($pdf->leftmargin, $pdf->GetY(), ($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin), 0.39); |
| | 439 | |
| | 440 | $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + .2); |
| | 441 | |
| | 442 | |
| | 443 | $this->receiptrecord["processedby"] = $this->receiptrecord["processorfirst"]." ".$this->receiptrecord["processorlast"]; |
| | 444 | $pdf->setStyle("normal"); |
| | 445 | |
| | 446 | foreach($this->topinfo as $column){ |
| | 447 | |
| | 448 | if($column->format != "") |
| | 449 | $value = formatVariable($this->receiptrecord[$column->fieldname], $column->format); |
| | 450 | else |
| | 451 | $value = $this->receiptrecord[$column->fieldname]; |
| | 452 | |
| | 453 | $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); |
| | 454 | |
| | 455 | }//end foreach |
| | 456 | |
| | 457 | $pdf->SetY($pdf->GetY() + 0.18 + 0.125); |
| | 458 | |
| | 459 | }//end method |
| | 460 | |
| | 461 | |
| | 462 | function _addLineItems($coords){ |
| | 463 | |
| | 464 | $pdf = &$this->pdf; |
| | 465 | |
| | 466 | $lineitemresult = $this->_getLineItems(); |
| | 467 | |
| | 468 | $pdf->setStyle("normal"); |
| | 469 | |
| | 470 | $pdf->SetY($pdf->GetY() + 0.18 + 0.0625); |
| | 471 | |
| | 472 | while($line = $this->db->fetchArray($lineitemresult)){ |
| | 473 | |
| | 474 | if($pdf->GetY() + 0.17*3 > $coords["y"] + $this->lineitemBoxHeight){ |
| | 475 | |
| | 476 | $pdf->SetLineWidth(0.02); |
| | 477 | $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); |
| | 478 | $pdf->SetLineWidth(0.01); |
| | 479 | |
| | 480 | $this->_addPage(); |
| | 481 | |
| | 482 | }//end if |
| | 483 | |
| | 484 | if($line["type"] == "invoice"){ |
| | 485 | |
| | 486 | $tempDate = stringToDate($line["itemdate"], "SQL"); |
| | 487 | $line["duedate"] = dateToString( strtotime(TERM1_DAYS." days", $tempDate), "SQL" ); |
| | 488 | |
| | 489 | } else |
| | 490 | $line["duedate"] = ""; |
| | 491 | |
| | 492 | if($line["type"] == "deposit" && $line["relatedid"] == $this->receiptrecord["id"]){ |
| | 493 | $line["relatedid"] = ""; |
| | 494 | $line["amount"] = 0; |
| | 495 | $line["aritemid"] = 0; |
| | 496 | } |
| | 497 | |
| | 498 | if($this->receiptrecord["posted"]) |
| | 499 | $line["docdue"] = $line["amount"] - $line["paid"]; |
| | 500 | elseif($line["relatedid"]) |
| | 501 | $line["docdue"] = $line["amount"] - $line["paid"] - $line["applied"] - $line["discount"] - $line["taxadjustment"]; |
| | 502 | else |
| | 503 | $line["docDue"] = 0; |
| | 504 | |
| | 505 | |
| | 506 | foreach($this->lineitems as $column){ |
| | 507 | |
| | 508 | $ln = 0; |
| | 509 | |
| | 510 | |
| | 511 | switch($column->fieldname){ |
| | 512 | |
| | 513 | case "parts": |
| | 514 | $pdf->SetFont("Arial", "B", 8); |
| | 515 | $pdf->Write(0.17, $line["partname"]); |
| | 516 | $pdf->setStyle("normal"); |
| | 517 | $pdf->SetX($pdf->leftmargin + $column->size); |
| | 518 | break; |
| | 519 | |
| | 520 | default: |
| | 521 | if($column->format != "") |
| | 522 | $value = formatVariable($line[$column->fieldname], $column->format); |
| | 523 | else |
| | 524 | $value = $line[$column->fieldname]; |
| | 525 | |
| | 526 | if($value == "·") |
| | 527 | $value = " "; |
| | 528 | |
| | 529 | if($column->fieldname == $this->lineitems[count($this->lineitems)-1]->fieldname) |
| | 530 | $ln = 2; |
| | 531 | |
| | 532 | $pdf->Cell($column->size, 0.17, $value, $pdf->borderDebug, $ln, $column->align); |
| | 533 | break; |
| | 534 | |
| | 535 | }//end switch |
| | 536 | |
| | 537 | }//end foreach |
| | 538 | |
| | 539 | $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); |
| | 540 | $pdf->SetLineWidth(0.01); |
| | 541 | $pdf->SetDrawColor(180,180,180); |
| | 542 | $pdf->Line($pdf->leftmargin, $pdf->GetY(), $pdf->paperwidth - $pdf->rightmargin, $pdf->GetY()); |
| | 543 | $pdf->SetDrawColor(0,0,0); |
| | 544 | $pdf->SetLineWidth(0.02); |
| | 545 | $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.0625); |
| | 546 | |
| | 547 | }//end while |
| | 548 | |
| | 549 | $pdf->SetLineWidth(0.02); |
| | 550 | $pdf->Rect($coords["x"], $coords["y"], $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $this->lineitemBoxHeight); |
| | 551 | |
| | 552 | }//end method |
| | 553 | |
| | 554 | |
| | 555 | function _getLineItems(){ |
| | 556 | |
| | 557 | $querystatement = " |
| | 558 | SELECT |
| | 559 | receiptitems.aritemid, |
| | 560 | receiptitems.applied, |
| | 561 | receiptitems.discount, |
| | 562 | receiptitems.taxadjustment, |
| | 563 | aritems.type, |
| | 564 | IF(`invoices`.`id`,`invoices`.`id`,`receipts`.`id`) AS `relatedid`, |
| | 565 | aritems.itemdate, |
| | 566 | aritems.amount, |
| | 567 | aritems.paid |
| | 568 | FROM |
| | 569 | ((receiptitems INNER JOIN aritems ON receiptitems.aritemid = aritems.uuid)LEFT JOIN `invoices` ON `aritems`.`relatedid` = `invoices`.`uuid`) LEFT JOIN `receipts` ON `aritems`.`relatedid` = `receipts`.`uuid` |
| | 570 | WHERE |
| | 571 | receiptitems.receiptid = '".mysql_real_escape_string($this->receiptrecord["uuid"])."' |
| | 572 | ORDER BY |
| | 573 | aritems.type, |
| | 574 | aritems.itemdate"; |
| | 575 | |
| | 576 | return $this->db->query($querystatement); |
| | 577 | |
| | 578 | }//end method |
| | 579 | |
| | 580 | |
| | 581 | function _addNotes(){ |
| | 582 | |
| | 583 | $pdf = &$this->pdf; |
| | 584 | |
| | 585 | $height = 1; |
| | 586 | $nextPos = $pdf->GetY() + $height + 0.125; |
| | 587 | |
| | 588 | $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); |
| | 589 | $pdf->setStyle("header"); |
| | 590 | $pdf->Cell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, 0.18, "Notes", 1, 2, "L", 1); |
| | 591 | |
| | 592 | $pdf->setStyle("normal"); |
| | 593 | $pdf->SetXY($pdf->GetX() + .06125, $pdf->GetY() + .06125); |
| | 594 | $pdf->MultiCell($pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin - 0.125, 0.18, $this->receiptrecord["memo"]); |
| | 595 | |
| | 596 | $pdf->SetXY($pdf->leftmargin, $nextPos); |
| | 597 | |
| | 598 | }//end method |
| | 599 | |
| | 600 | |
| | 601 | function _addTotals(){ |
| | 602 | |
| | 603 | $pdf = &$this->pdf; |
| | 604 | |
| | 605 | $size = $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin; |
| | 606 | |
| | 607 | $tempTotalsinfo = $this->totalsinfo; |
| | 608 | |
| | 609 | if($this->receiptrecord["remaining"]){ |
| | 610 | |
| | 611 | $this->totalsinfo[1]->size = 1; |
| | 612 | $size -= 1; |
| | 613 | |
| | 614 | } else |
| | 615 | array_shift($this->totalsinfo); |
| | 616 | |
| | 617 | $this->totalsinfo[0]->size = $size; |
| | 618 | |
| | 619 | $height = .5; |
| | 620 | $nextPos = $pdf->GetY() + $height + 0.125; |
| | 621 | |
| | 622 | $pdf->Rect($pdf->GetX(), $pdf->GetY(), $pdf->paperwidth - $pdf->leftmargin - $pdf->rightmargin, $height); |
| | 623 | |
| | 624 | $pdf->setStyle("header"); |
| | 625 | |
| | 626 | foreach($this->totalsinfo as $column) |
| | 627 | $pdf->Cell($column->size, 0.18, $column->title, 1, 0, $column->align, 1); |
| | 628 | |
| | 629 | $pdf->setStyle("normal"); |
| | 630 | $pdf->SetFont("Arial", "B", 10); |
| | 631 | $pdf->SetXY($pdf->leftmargin, $pdf->GetY() + 0.18 + 0.0625); |
| | 632 | |
| | 633 | foreach($this->totalsinfo as $column){ |
| | 634 | |
| | 635 | if($column->format != "") |
| | 636 | $value = formatVariable($this->receiptrecord[$column->fieldname], $column->format); |
| | 637 | else |
| | 638 | $value = $this->receiptrecord[$column->fieldname]; |
| | 639 | |
| | 640 | $pdf->Cell($column->size, 0.18, $value, $pdf->borderDebug, 0, $column->align); |
| | 641 | |
| | 642 | }//end foreach |
| | 643 | |
| | 644 | if(isset($this->totalsinfo[1])) |
| | 645 | $this->totalsinfo[1]->size = 0; |
| | 646 | |
| | 647 | $pdf->SetXY($pdf->leftmargin, $nextPos); |
| | 648 | |
| | 649 | $this->totalsinfo = $tempTotalsinfo; |
| | 650 | |
| | 651 | }//end method |
| | 652 | |
| | 653 | |
| | 654 | |
| | 655 | function output($destination = "screen" , $userinfo = NULL){ |
| | 656 | |
| | 657 | switch($destination){ |
| | 658 | |
| | 659 | case "screen": |
| | 660 | $userinfo = cleanFilename((string)$userinfo); |
| | 661 | $this->pdf->Output($userinfo, 'D'); |
| | 662 | break; |
| | 663 | |
| | 664 | case "email": |
| | 665 | |
| | 666 | if(!$userinfo) |
| | 667 | $userinfo = $_SESSION["userinfo"]; |
| | 668 | |
| | 669 | if(!$userinfo["email"] || !$this->receiptrecord["email"]) |
| | 670 | return false; |
| | 671 | |
| | 672 | $pdf = $this->pdf->Output(NULL, "S"); |
| | 673 | |
| | 674 | $to = $this->receiptrecord["email"]; |
| | 675 | $from = $userinfo["email"]; |
| | 676 | $subject = "Your ".$this->settings["reportTitle"]." from ".COMPANY_NAME; |
| | 677 | $message = "Attached is your ".$this->settings["reportTitle"]." from ".COMPANY_NAME."\n\n" . |
| | 678 | "The attachment requires Adobe Acrobat Reader to view. \n If you do not " . |
| | 679 | "have Acrobat Reader, you can download it at http://www.adobe.com \n\n" . |
| | 680 | COMPANY_NAME."\n". |
| | 681 | COMPANY_ADDRESS."\n".COMPANY_CSZ."\n".COMPANY_PHONE; |
| | 682 | |
| | 683 | $headers = "From: $from"; |
| | 684 | |
| | 685 | $semi_rand = md5( time() ); |
| | 686 | $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; |
| | 687 | |
| | 688 | $headers .= "\nMIME-Version: 1.0\n" . |
| | 689 | "Content-Type: multipart/mixed;\n" . |
| | 690 | " boundary=\"{$mime_boundary}\""; |
| | 691 | |
| | 692 | $message = "This is a multi-part message in MIME format.\n\n" . |
| | 693 | "--{$mime_boundary}\n" . |
| | 694 | "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . |
| | 695 | "Content-Transfer-Encoding: 7bit\n\n" . |
| | 696 | $message . "\n\n"; |
| | 697 | |
| | 698 | $pdf = chunk_split( base64_encode( $pdf ) ); |
| | 699 | |
| | 700 | $message .= "--{$mime_boundary}\n" . |
| | 701 | "Content-Type: {application/pdf};\n" . |
| | 702 | " name=\"".$this->settings["reportTitle"].$this->receiptrecord["id"]."\"\n" . |
| | 703 | "Content-Disposition: attachment;\n" . |
| | 704 | " filename=\"".$this->settings["reportTitle"].$this->receiptrecord["id"].".pdf\"\n" . |
| | 705 | "Content-Transfer-Encoding: base64\n\n" . |
| | 706 | $pdf . "\n\n" . |
| | 707 | "--{$mime_boundary}--\n"; |
| | 708 | |
| | 709 | return @ mail($to, $subject, $message, $headers); |
| | 710 | |
| | 711 | break; |
| | 712 | |
| | 713 | }//endswitch |
| | 714 | |
| | 715 | }//end method |
| | 716 | |
| | 717 | /** |
| | 718 | * function addingRecordDefaultSettings |
| | 719 | * |
| | 720 | * Creates an array of settings associative arrays for use by the system when |
| | 721 | * a new report record is added that references the file containing this class |
| | 722 | * |
| | 723 | * @retrun array of settings. Each setting should itself be |
| | 724 | * an associative array containing the following |
| | 725 | * name: name of the setting |
| | 726 | * defaultvalue: default value for setting |
| | 727 | * type: (string, int, real, bool) type for value of setting |
| | 728 | * required: (0,1) whether the setting is required or not |
| | 729 | * description: brief description for what this setting is used for. |
| | 730 | */ |
| | 731 | function addingRecordDefaultSettings(){ |
| | 732 | |
| | 733 | $settings[] = array( |
| | 734 | "name"=>"reportTitle", |
| | 735 | "defaultValue"=>"Receipt", |
| | 736 | "type"=>"string", |
| | 737 | "required"=>1, |
| | 738 | "description"=>"Title printed in upper right hand of report." |
| | 739 | ); |
| | 740 | |
| | 741 | return $settings; |
| | 742 | |
| | 743 | }//endfunction addingRecordDefaultSettings |
| | 744 | |
| | 745 | }//end class |
| | 746 | |
| | 747 | |
| | 748 | /** |
| | 749 | * PROCESSING |
| | 750 | * ============================================================================= |
| | 751 | */ |