Sorgumu nasıl değiştirmeliyim - R10.net
  • 24-11-2021, 23:01:04
    #1
    Arkadaşlar gerekirse ücretli bir şekilde yardm almak istiyorum. Sorunu çözmem lazım :/

    Konunun tam adının ne olduğunu bilmediğim için öyle yazdım. Girilen rezervasyonları dışa aktarım yaptım excel için. Ancak 1 alan var ki onu alamıyorum çünkü nasıl olacağını bilmiyorum.

    Bu alan form alanım.

    <div class="modal fade" id="kt_customers_export_modal" tabindex="-1" aria-hidden="true">
           <!--begin::Modal dialog-->
           <div class="modal-dialog modal-dialog-centered mw-650px">
               <!--begin::Modal content-->
               <div class="modal-content">
                   <!--begin::Modal header-->
                   <div class="modal-header">
                       <!--begin::Modal title-->
                       <h2 class="fw-bolder">Reservation Reports</h2>
                       <!--end::Modal title-->
                       <!--begin::Close-->
                       <div id="kt_customers_export_close" class="btn btn-icon btn-sm btn-active-icon-primary">
                           <!--begin::Svg Icon | path: icons/duotune/arrows/arr061.svg-->
                           <span class="svg-icon svg-icon-1">
          <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
                                                    viewBox="0 0 24 24" fill="none">
             <rect opacity="0.5" x="6" y="17.3137" width="16" height="2"
                                                         rx="1" transform="rotate(-45 6 17.3137)" fill="black"/>
             <rect x="7.41422" y="6" width="16" height="2" rx="1"
                                                         transform="rotate(45 7.41422 6)" fill="black"/>
          </svg>
       </span>
                           <!--end::Svg Icon-->
                       </div>
                       <!--end::Close-->
                   </div>
                   <!--end::Modal header-->
                   <!--begin::Modal body-->
                   <div class="modal-body scroll-y mx-5 mx-xl-15 my-7">
                       <!--begin::Form-->
                       <form id="kt_careers_form" class="form" action="settings/edit-process.php">
                           <!--begin::Input group-->
                           <div class="row">
                               <div class="fv-row mb-5 col-md-6">
                                   <!--begin::Label-->
                                   <label class="fs-5 fw-bold form-label mb-5">Start Date:</label>
                                   <!--end::Label-->
                                   <!--begin::Input-->
                                   <input class="form-control form-control-solid" placeholder="Pick a date"
                                          name="start_date" required/>
                                   <!--end::Input-->
                               </div>
                               <div class="fv-row mb-5 col-md-6">
                                   <!--begin::Label-->
                                   <label class="fs-5 fw-bold form-label mb-5">End Date:</label>
                                   <!--end::Label-->
                                   <!--begin::Input-->
                                   <input class="form-control form-control-solid" placeholder="Pick a date"
                                          name="end_date" required/>
                                   <!--end::Input-->
                               </div>
                           </div>
                           <!--end::Input group-->
                           <!--begin::Input group-->
                           <!--end::Input group-->
                           <!--begin::Row-->
                           <div class="row fv-row mb-15">
                               <!--begin::Radio group-->
                               <div class="fv-row mb-10">
                                   <!--begin::Label-->
                                   <label class="fs-5 fw-bold form-label mb-5">Source:</label>
                                   <!--end::Label-->
                                   <!--begin::Input-->
                                   <select name="source" class="form-select form-select-lg form-select-solid"
                                           data-control="select2" data-placeholder="Select..."
                                           data-allow-clear="true" data-hide-search="true">
                                       <option value="ALL">ALL</option>
                                       <?php
                                       $i = 1;
                                       foreach ($Source as $data) { ?>
                                           $i++;
       <option value="<?= $data['source'] ?>"><?= $data['source'] ?></option>
       
                                       <?php } ?>
                                   </select>
                                   <!--end::Input-->
                               </div>
                           </div>
                           <!--end::Row-->
                           <!--begin::Actions-->
                           <div class="text-center">
                               <button type="reset" id="kt_customers_export_cancel" class="btn btn-light me-3">
                                   İptal
       </button>
                               <button type="submit" name="datereport" class="btn btn-primary">
                                   <span class="indicator-label">Tamam</span>
                                   <span class="indicator-progress">Please wait...
       <span class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
                               </button>
                           </div>
                           <!--end::Actions-->
                       </form>
                       <!--end::Form-->
                   </div>
                   <!--end::Modal body-->
               </div>
               <!--end::Modal content-->
           </div>
           <!--end::Modal dialog-->
       </div>



    Bu alanda da formu karşılıyorum ve işlem yaptırıyorum.


    if (isset($_GET['source']) AND $_GET['source'] == "ALL")  {
       
           $info=$db->prepare("SELECT * from reservations");
           $info->execute();
           $items=$info->fetch(PDO::FETCH_ASSOC);
       
           $items['start_date'];
           $items['source'];
           $items['source_name'];
           $items['pax'];
           $items['incoming_pax'];
           $items['net_check_amount'];
       
           $start_date = date('Y-m-d', strtotime($_GET['start_date']));
           $end_date = date('Y-m-d', strtotime($_GET['end_date']));
           $sql = "SELECT * FROM reservations WHERE start_date BETWEEN '" . $start_date . "' AND '". $end_date ."' ORDER BY id ASC";
           $excelVeri=$db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
       
       
           $MyExcel=new PHPExcel();
           $MyExcel->getActiveSheet()->setTitle("RBM-Reports");
           $MyExcel->getActiveSheet()->setCellValue("A1","DATE");
           $MyExcel->getActiveSheet()->setCellValue("B1","SOURCE");
           $MyExcel->getActiveSheet()->setCellValue("C1","SOURCE NAME");
           $MyExcel->getActiveSheet()->setCellValue("D1","NUMBER OF RESERVATIONS");
           $MyExcel->getActiveSheet()->setCellValue("E1","RESERVATION PAX");
           $MyExcel->getActiveSheet()->setCellValue("F1","INCOMING PAX");
           $MyExcel->getActiveSheet()->setCellValue("G1","NET CHECK AMOUNT");
           $MyExcel->getActiveSheet()->getColumnDimension('A')->SetAutoSize(true);
           $MyExcel->getActiveSheet()->getColumnDimension('B')->SetAutoSize(true);
           $MyExcel->getActiveSheet()->getColumnDimension('C')->SetAutoSize(true);
           $MyExcel->getActiveSheet()->getColumnDimension('D')->SetAutoSize(true);
           $MyExcel->getActiveSheet()->getColumnDimension('E')->SetAutoSize(true);
           $MyExcel->getActiveSheet()->getColumnDimension('F')->SetAutoSize(true);
           $MyExcel->getActiveSheet()->getColumnDimension('G')->SetAutoSize(true);
           $MyExcel->getActiveSheet()->getRowDimension("1")->setRowHeight(27);
           $MyExcel->getActiveSheet()->getStyle("A1:G1")
                                     ->getFill()
                                     ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
                                     ->getStartColor()->setRGB('EBAB9E');
           $MyExcel->getActiveSheet()->getStyle("A1:G1")->getFont()->setBold(true);
           $borderstyle=array(
               'borders' => array (
                   'allborders' => array (
                       'style' =>PHPExcel_Style_Border::BORDER_THIN
                   )
               )
           );
       
           $MyExcel->getActiveSheet()->getStyle("A1:G1")->getFont()->setSize(13);
           $MyExcel->getActiveSheet()->getStyle("A1:G1")->applyFromArray($borderstyle);
       
       
           $i=2;
           foreach($excelVeri as $items) {
           $MyExcel->getActiveSheet()->getRowDimension($i)->setRowHeight(22);
           $MyExcel->getActiveSheet()->getStyle("A$i:G$i")->applyFromArray($borderstyle);
           $MyExcel->getActiveSheet()->getStyle("A$i:G$i")->getFont()->setSize(12);
           $MyExcel->getActiveSheet()->setCellValue("A".$i,$items['start_date']);
           $MyExcel->getActiveSheet()->setCellValue("B".$i,$items['source']);
           $MyExcel->getActiveSheet()->setCellValue("C".$i,$items['source_name']);
           $MyExcel->getActiveSheet()->setCellValue("D".$i,$items['source_name']);
           $MyExcel->getActiveSheet()->setCellValue("E".$i,$items['pax']);
           $MyExcel->getActiveSheet()->setCellValue("F".$i,$items['incoming_pax']);
           $MyExcel->getActiveSheet()->setCellValue("G".$i,$items['net_check_amount']);
           $i++;
       
           }
           header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
           header('Content-Disposition: attachment;filename="RBM-Reports.xlsx"');
           header('Cache-Control: max-age=0');
           header('Cache-Control: max-age=1');
           header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
           header('Last-Modified:'.gmdate('D, d M Y H:i:s').'GMT');
           header('Cache-Control: cache, must-revalidate');
           header('Pragma: public');
       
           $save=PHPExcel_IOFactory::createWriter($MyExcel, 'Excel2007');
           $save->save('php://output');
           exit;
       
       
       }


    Veritabanı yapısıda burada.



    Sorum şu;

    Dışa aktarma da kullandığım veriler içerisinde yukarıda Number of Reservations alanı var. Bu alanı, source kaynagı belirtilirse eger rapor esnasında o source alanına ne kadar aıt rezervasyon varsa onlarla beraber hesaplasın ıstıyorum. Bir de rapor almak istediğimde export işlemi hatalı sayfaya gidiyor ama excel indiriyor sadece ALL işaretlersem. Eğer seceneklerde baska bir kaynak varsa hata veriyor excel indirmiyor.

    Şimdiden çok teşekkür ederim.