void MainTabSaleItemController::printDocument()
{
    PrintSaleDocumentController *pc = new PrintSaleDocumentController(view->getTableView()->getSymbol());
    if(view->getTableView()->getSymbol() == "")
    {
        MessageBox *messageBox = new MessageBox();
        messageBox->createInfoBox("Zaznacz dokument do druku");
        delete messageBox;
    }
    else if(view->getTableView()->getSymbol().contains("FK"))
    {
        DocumentFK doc = fkService->getDocumentFK(view->getTableView()->getSymbol());
        pc->print(&doc);
    }
    else
    {
         DocumentZAL docZal;
         docZal= zalService->getDocumentZAL(view->getTableView()->getSymbol());
         if(docZal.getDocumentType().contains("RZL")||docZal.getDocumentType().contains("ZAL"))
         {
             pc->print(&docZal);
         }
         else
         {
             Invoice doc = invoiceService->getInvoice(view->getTableView()->getSymbol());
             pc->print(&doc);

         }
    }
    delete pc;
}
void MainTabSaleItemController::dialogDocumentEdit()
{
    if(view->getTableView()->getSymbol() == "")
    {
        MessageBox *messageBox = new MessageBox();
        messageBox->createInfoBox("Zaznacz dokument do edycji");
        delete messageBox;
    }
    else if (view->getTableView()->getSymbol().contains("PA"))
    {
        DocumentPAController dialog(this,1);
        dialog.exec(view->getTableView()->getSymbol());
        documentTVModel->getDocuments();
    }
    else if (view->getTableView()->getSymbol().contains("FK"))
    {
        DocumentFKController dialog(this,1);
        dialog.exec(view->getTableView()->getSymbol());
        documentTVModel->getDocuments();
    }
    else if (view->getTableView()->getSymbol().section("/",0,0)=="FM")
    {
        DocumentFMController dialog(this,"FM",1);
        dialog.exec(view->getTableView()->getSymbol());
        documentTVModel->getDocuments();
    }

    else if (view->getTableView()->getSymbol().contains("FV")||view->getTableView()->getSymbol().contains("FMP")
             ||view->getTableView()->getSymbol().contains("PRO")||view->getTableView()->getSymbol().contains("PI"))
    {
        DocumentZAL doc;
        doc= zalService->getDocumentZAL(view->getTableView()->getSymbol());
         if(doc.getDocumentType().contains("RZL")||doc.getDocumentType().contains("ZAL"))
        {   DocumentZALController*dialog;

            if(doc.getDocumentType().contains("RZL"))
            dialog = new DocumentZALController(this,"RZL",1);
            else
            dialog = new DocumentZALController(this,"ZAL",1);

            dialog->exec(view->getTableView()->getSymbol());
            documentTVModel->getDocuments();
            delete dialog;
        }
        else
         {
        InvoiceController dialog(this,view->getTableView()->getSymbol().section("/",0,0),1);
        dialog.exec(view->getTableView()->getSymbol());
        documentTVModel->getDocuments();
         }
    }
}
void MainTabOrderItemController::dialogDocumentEdit()
{
    if(view->getTableView()->getSymbol() == "")
    {
         MessageBox *messageBox = new MessageBox();
         messageBox->createInfoBox("Zaznacz dokument do edycji");
         delete messageBox;
    }
    else if(view->getTableView()->getSymbol().contains("ZD")||view->getTableView()->getSymbol().contains("ZK"))
    {
         OrderController dialog(this,view->getTableView()->getSymbol().section("/",0,0),1);
         dialog.exec(view->getTableView()->getSymbol());
         documentTVModel->getDocuments();
    }
}
void MainTabOrderItemController::printDocument()
{
    PrintOrderDocumentController *pc = new PrintOrderDocumentController(view->getTableView()->getSymbol());
    if(view->getTableView()->getSymbol() == "")
    {
        MessageBox *messageBox = new MessageBox();
        messageBox->createInfoBox("Zaznacz dokument do druku");
        delete messageBox;
    }
    else
    {
        Order doc = orderService->getOrder(view->getTableView()->getSymbol());
        pc->print(&doc);
    }
    delete pc;
}
void MainTabSaleItemController::removeDocument()
{
    MessageBox *msgBox = new MessageBox();

    bool storeUpdate = false;

    if(view->getTableView()->getId()==-1)
    {
        msgBox->createInfoBox("Zaznacz dokument do usunięcia");
    }

    if(view->getTableView()->getSymbol().contains("FV")||view->getTableView()->getSymbol().contains("FMP")||view->getTableView()->getSymbol().contains("PRO")
        ||view->getTableView()->getSymbol().contains("PI")||view->getTableView()->getSymbol().contains("PA")||view->getTableView()->getSymbol().section("/",0,0)=="FM")
    {
        if(msgBox->createQuestionBox("Usuwanie dokumentu " +view->getTableView()->getSymbol())== MessageBox::YES)
        {

            if(invoiceService->getInvoice(view->getTableView()->getSymbol()).getStoreResult())
              {
                   if(msgBox->createQuestionBox("Usunięto dokument "+view->getTableView()->getSymbol(),"Cofnąć skutek magazynowy?")==MessageBox::YES)
                    storeUpdate=true;
              }
        invoiceService->removeInvoice(view->getTableView()->getSymbol(),storeUpdate);
        }
    }

    if(view->getTableView()->getSymbol().contains("FK"))
    {
        if( msgBox->createQuestionBox("Usuwanie dokumentu " +view->getTableView()->getSymbol())== MessageBox::YES)
        {

            if(fkService->getDocumentFK(view->getTableView()->getSymbol()).getStoreResult())
            {
                if(msgBox->createQuestionBox("Usunięto dokument "+view->getTableView()->getSymbol(),"Cofnąć skutek magazynowy?")==MessageBox::YES)
                  storeUpdate=true;
            }
        fkService->removeDocumentFK(view->getTableView()->getSymbol(),storeUpdate);
        }
    }

    delete msgBox;
    documentTVModel->getDocuments();
}