<?php

header("X-Content-Type-Options: nosniff");
header("X-XSS-Protection: 1; mode=block");
header("X-Frame-Options: DENY");
header('Expires: Sun, 01 Jan 2000 00:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');

ini_set('session.cookie_httponly', 'on');
ini_set('session.cookie_secure', 'on');

session_name("SIGNADMAUTH");
session_start();

include "common/config/config.php";
include "common/config/dbconfig.php";
include "common/functions/funcconnect.php";
include "common/functions/funcauthen.php";
openDB();

if (!authen())
{ header ("location: login.php");
		}
else
{ $qord="SELECT a.*,
																IF (a.catatan IS NOT NULL AND a.catatan<>'', a.catatan, '-') AS ordernote,
																IF (a.statustandajadi=1, 'Sukses', 'Gagal') AS statusbayardp,
																b.namacarabayartandajadi
									FROM $db_pesanan a
									LEFT JOIN $db_carabayartandajadi b ON a.idcarabayartandajadi=b.idcarabayartandajadi 
									WHERE a.statustandajadi='1'
															AND a.statusorder<'5'
									ORDER BY a.idpesanan ASC
									";
		$rord=mysqli_query($dbConnection, $qord);
		// echo $qord."<br><br>".mysqli_error($dbConnection)."<br><br>";
		// exit;
		// D3D6C1C0969F
		if (mysqli_num_rows($rord)>0)
		{ $allorder="";
				while ($dord=mysqli_fetch_array($rord))
				{ $produkdipesan="";
						$qpd="SELECT i.*,
																			a.iditem,
																			b.kodekategoribarang, b.namakategoribarang,
																			c.kodemerek, c.namamerek,
																			d.kodemodel, d.namamodel,
																			e.kodewarna, e.namawarna, e.kodehtml,
																			f.thnproduksi,
																			g.iditemprice, g.ontheroad,
																			h.namawilayahotr
												FROM $db_pesanandetail i
												LEFT JOIN $db_item a ON i.iditem=a.iditem 
												LEFT JOIN $db_kategoribarang b ON a.idkategoribarang=b.idkategoribarang 
												LEFT JOIN $db_merek c ON a.idmerek=c.idmerek 
												LEFT JOIN $db_model d ON a.idmodel=d.idmodel 
												LEFT JOIN $db_warna e ON a.idwarna=e.idwarna 
												LEFT JOIN $db_thnproduksi f ON a.idthnproduksi=f.idthnproduksi 
												LEFT JOIN $db_itemprice g ON d.idmodel=g.idmodel AND i.iditemprice=g.iditemprice 
												LEFT JOIN $db_wilayahotr h ON g.idwilayahotr=h.idwilayahotr 
												WHERE i.nomorpesanan='".$dord['nomorpesanan']."'
																		AND i.sesipesanan='".$dord['sesipesanan']."'
												ORDER BY i.idpesanandetail ASC
												";
						$rpd=mysqli_query($dbConnection, $qpd);
						while ($dpd=mysqli_fetch_array($rpd))
						{ if (empty($dpd['ontheroad']))
								{ $ontrharga="OFF-THE-ROAD ";
										}
								else
								{ $ontrharga="ON-THE-ROAD ";
										}
								if (!empty($produkdipesan))
								{ $produkdipesan.="<br><br>";
										}
								$produkdipesan.=$dpd['jumlahpesan']." UNIT ".strtoupper($dpd['namamerek'])." ".strtoupper($dpd['namamodel'])."<br>
																								".strtoupper($dpd['namawarna'])." THN ".$dpd['thnproduksi']."<br>
																								".$ontrharga." ".strtoupper($dpd['namawilayahotr'])."<br>
																								Rp. ".number_format($dpd['hargajual'], 0, ",", ".");
								}
						$tandajadi="<span class='material-icons' style='color:#33aa88'>payments</span>";
						$tandajadilink="<span style='color:#33aa88; font-weight:bold'>Tanda Jadi</span>";
						$lihatdata="<a href='pesanan_lihat.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'><span class='material-icons'>pageview</span></a>";
						$lihatdatalink="<a href='pesanan_lihat.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'>Lihat Data</a>";
						if ($dord['statusorder']==1) // buyer sudah bayar tanda jadi
						{ $konfirmasi="<a href='konfirmasidata.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'><span class='material-icons-outlined'>3p</span></a>";
								$konfirmasilink="<a href='konfirmasidata.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'>Periksa Data</a>";
								$paylunas="<span class='material-icons-outlined' style='color:#acbccc'>fact_check</span>";
								$paylunaslink="<font color='#acbccc'>Bayar Lunas</font>";
								$pengajuanfaktur="<span class='material-icons-outlined' style='color:#acbccc'>folder_shared</span>";
								$pengajuanfakturlink="<font color='#acbccc'>Pengajuan Faktur</font>";
								$kirimok="<span class='material-icons-outlined' style='color:#acbccc'>delivery_dining</span>";
								$kirimoklink="<font color='#acbccc'>Pengiriman</font>";
								$batal="<span class='material-icons-outlined' style='color:#acbccc'>disabled_by_default</span>";
								$batallink="<font color='#acbccc'>Batalkan</font>";
								}
						else if ($dord['statusorder']==2) // periksa data sudah dilakukan
						{ $konfirmasi="<span class='material-icons'<span style='color:#33aa88'>3p</span>";
								$konfirmasilink="<span style='color:#33aa88; font-weight:bold'>Periksa Data</span>";
								$paylunas="<a href='konfirmasilunas.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'><span class='material-icons-outlined'>fact_check</span></a>";
								$paylunaslink="<a href='konfirmasilunas.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'>Bayar Lunas</a>";
								$pengajuanfaktur="<span class='material-icons-outlined'>folder_shared</span>";
								$pengajuanfakturlink="Pengajuan Faktur";
								$kirimok="<span class='material-icons-outlined' style='color:#acbccc'>delivery_dining</span>";
								$kirimoklink="<font color='#acbccc'>Pengiriman</font>";
								$batal="<a href='konfirmasidokumen.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'><span class='material-icons-outlined'>disabled_by_default</span></a>";
								$batallink="<a href='konfirmasidokumen.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'>Batalkan</a>";
								}
						else if ($dord['statusorder']==3) // buyer bayar lunas -> kalau kredit = bayar TDP, kalau tunai = bayar full
						{ $konfirmasi="<span class='material-icons'>3p</span>";
								$konfirmasilink="Periksa Data";
								$paylunas="<span class='material-icons-outlined'>fact_check</span>";
								$paylunaslink="Bayar Lunas";
								$pengajuanfaktur="<a href='konfirmasidokumen.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'><span class='material-icons-outlined'>folder_shared</span></a>";
								$pengajuanfakturlink="<a href='konfirmasidokumen.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'>Pengajuan Faktur</a>";
								$kirimok="<span class='material-icons-outlined' style='color:#acbccc'>delivery_dining</span>";
								$kirimoklink="<font color='#acbccc'>Pengiriman</font>";
								$batal="<a href='konfirmasidokumen.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'><span class='material-icons-outlined'>disabled_by_default</span></a>";
								$batallink="<a href='konfirmasidokumen.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'>Batalkan</a>";
								}
						else if ($dord['statusorder']==4) // pengajuan faktur sudah dilakukan
						{ $konfirmasi="<span class='material-icons'>3p</span>";
								$konfirmasilink="Periksa Data";
								$paylunas="<span class='material-icons-outlined'>fact_check</span></a>";
								$paylunaslink="Bayar Lunas";
								$pengajuanfaktur="<span class='material-icons-outlined'>folder_shared</span>";
								$pengajuanfakturlink="Pengajuan Faktur";
								$kirimok="<a href='pengiriman.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'><span class='material-icons-outlined' style='color:#acbccc'>delivery_dining</span></a>";
								$kirimoklink="<a href='pengiriman.php?idp=".$dord['idpesanan']."&oid=".base64_encode($dord['nomorpesanan'])."'><font color='#acbccc'>Pengiriman</font></a>";
								$batal="<span class='material-icons-outlined'>disabled_by_default</span>";
								$batallink="Batalkan";
								}
						/*
						else if ($dord['statusorder']==5 || $dord['statusorder']==6 || $dord['statusorder']==7) // pengiriman sudah dilakukan, atau stnk ok, atau bpkb ok
						{ $konfirmasi="<span class='material-icons'>3p</span>";
								$konfirmasilink="Periksa Data";
								$paylunas="<span class='material-icons-outlined'>fact_check</span></a>";
								$paylunaslink="Bayar Lunas";
								$pengajuanfaktur="<span class='material-icons-outlined'>folder_shared</span>";
								$pengajuanfakturlink="Pengajuan Faktur";
								$kirimok="<span class='material-icons-outlined' style='color:#acbccc'>delivery_dining</span>";
								$kirimoklink="<font color='#acbccc'>Pengiriman</font>";
								$batal="<span class='material-icons-outlined'>disabled_by_default</span>";
								$batallink="Batalkan";
								}
						else if ($dord['statusorder']==8) // pesanan dibatalkan
						{ $konfirmasi="<span class='material-icons-outlined'>3p</span>";
								$konfirmasilink="<del style='text-decoration-style:double'>Periksa Data</del>";
								$paylunas="<span class='material-icons-outlined'>fact_check</span>";
								$paylunaslink="<del style='text-decoration-style:double'>Bayar Lunas</del>";
								$pengajuanfaktur="<span class='material-icons-outlined'>folder_shared</span>";
								$pengajuanfakturlink="<del style='text-decoration-style:double'>Pengajuan Faktur</del>";
								$kirimok="<span class='material-icons-outlined'>delivery_dining</span>";
								$kirimoklink="<del style='text-decoration-style:double'>Pengiriman</del>";
								$batal="<span class='material-icons-outlined'>disabled_by_default</span>";
								$batallink="<del style='text-decoration-style:double'>Batalkan</del>";
								}
						*/
						$action="<table class='' border='0' cellpadding='0' cellspacing='0'>
																<tr style='background-color:transparent'>
																	<td align='left' valign='top' style='all:revert; padding-right:5px'>
																		".$lihatdata."
																	</td>
																	<td align='left' valign='top' style='all:revert; font-size:8pt' nowrap>
																		".$lihatdatalink."
																	</td>
																</tr>	
																<tr style='background-color:transparent'>
																	<td align='left' valign='top' style='all:revert; padding-right:5px'>
																		".$tandajadi."
																	</td>
																	<td align='left' valign='top' style='all:revert; font-size:8pt' nowrap>
																		".$tandajadilink."
																	</td>
																</tr>	
																<tr style='background-color:transparent'>
																	<td align='left' valign='top' style='all:revert; padding-right:5px'>
																		".$konfirmasi."
																	</td>
																	<td align='left' valign='top' style='all:revert; font-size:8pt' nowrap>
																		".$konfirmasilink."
																	</td>
																</tr>
																<tr style='background-color:transparent'>
																	<td align='left' valign='top' style='all:revert; padding-right:5px'>
																		".$paylunas."
																	</td>
																	<td align='left' valign='top' style='all:revert; font-size:8pt' nowrap>
																		".$paylunaslink."
																	</td>
																</tr>
																<tr style='background-color:transparent'>
																	<td align='left' valign='top' style='all:revert; padding-right:5px'>
																		".$pengajuanfaktur."
																	</td>
																	<td align='left' valign='top' style='all:revert; font-size:8pt' nowrap>
																		".$pengajuanfakturlink."
																	</td>
																</tr>
																<tr style='background-color:transparent'>
																	<td align='left' valign='top' style='all:revert; padding-right:5px'>
																		".$kirimok."
																	</td>
																	<td align='left' valign='top' style='all:revert; font-size:8pt' nowrap>
																		".$kirimoklink."
																	</td>
																</tr>
																<tr style='background-color:transparent'>
																	<td align='left' valign='top' style='all:revert; padding-right:5px'>
																		".$batal."
																	</td>
																	<td align='left' valign='top' style='all:revert; font-size:8pt' nowrap>
																		".$batallink."
																	</td>
																</tr>
															</table>
															";
						$allorder.="<tr>
																			<td align='left' valign='top' nowrap>
																				".date("d-m-Y H:i:s", strtotime($dord['waktutandajadi']))."<br>
																				No.: ".$dord['nomorpesanan']."
																			</td>
																			<td align='left' valign='top'>
																				".strtoupper($dord['namalengkap'])."<br>
																				".$dord['noktp']."<br>
																				".strtoupper($dord['alamatlengkap'])."<br>
																				".$dord['nohandphone']."<br>
																			</td>
																			<td align='left' valign='top'>
																				".$produkdipesan."
																			</td>
																			<td align='left' valign='top' nowrap>
																				Rp. ".number_format($dord['totaltandajadi'], 0, ",", ".")."<br>
																				".$dord['namacarabayartandajadi']."<br>
																				".date("d-m-Y H:i:s", strtotime($dord['waktutandajadi']))."<br>
																				".strtoupper($dord['statusbayardp'])."
																			</td>
																			<td align='left' valign='top' nowrap>
																				".strtoupper($dord['ordernote'])."
																			</td>
																			<td align='left' valign='top' nowrap>
																				".$action."
																			</td>
																		</tr>
																		";
						}
				}
		else
		{ $allorder="<tr>
																<td align='center' valign='center' colspan='5' height='50px'>
																	Tidak ada pesanan yang belum diproses
																</td>
															</tr>
															";
				}
		$content="<table border='0' cellpadding='0' cellspacing='0' width='100%'>
													<tr>
														<td align='left' valign='top' width='100%'>
															<div style='border:2px solid #ffaaaa; padding:10px; background-color:#ffefef; line-height:18px; font-weight:bold; font-size:10pt'>
																Semua data dan informasi bersifat sangat rahasia oleh karena itu menyalinnya, 
																menyimpannya, atau membagikannya dengan lalai dan/atau tanpa izin akan diproses sesuai aturan
																yang berlaku di DigimaxOTO dan hukum serta undang-undang yang berlaku di negara Republik Indonesia.
															</div>	
															<br><br>
															<b class='title'>PESANAN BELUM SELESAI</b>
															<br><hr size='1' color='#000000'><br>
															<table border='0' cellpadding='0' cellspacing='0' width='100%'>
																<tr>
																	<td align='left' valign='top' width='100%'>
																		<table id='' class='display'>
																			<thead>
																				<tr>
																					<th align='center' valign='middle' nowrap>
																						<b>Pesanan</b>
																					</th>
																					<th align='center' valign='middle' width='22%' nowrap>
																						<b>Pembeli</b>
																					</th>
																					<th align='center' valign='middle' width='20%' nowrap>
																						<b>Produk Dipesan</b>
																					</th>
																					<th align='center' valign='middle' nowrap>
																						<b>Tanda Jadi</b>
																					</th>
																					<th align='center' valign='middle' width='15%' nowrap>
																						<b>Catatan</b>
																					</th>
																					<th align='center' valign='middle' nowrap>
																						<b>Tindakan</b>
																					</th>
																				</tr>
																			</thead>
																			<tbody>	
																				".$allorder."
																			</tbody>	
																		</table>
																	</td>
																</tr>
															</table>
														</td>
													</tr>
												</table>
												";
		}

include "webmenu.php";
include "common/include/template.php";
$temp=new template;
$temp->define_theme("themes/theme1.html");
$temp->define_tag("{PAGETITLE}", $namaaplikasi);
$temp->define_tag("{NAMAUSER}", strtoupper($_SESSION['SES_FULLNAME']));
$temp->define_tag("{APPMENU}", $webmenu);
$temp->define_tag("{APPCONTENT}", $content);
$temp->parse();
$temp->printproses();

closeDB();

?>