Exemple #1
0
void arWorkBench::sCCRefundCM()
{
    if (_aropenCM->altId() < 0)
    {
        QMessageBox::warning(this, tr("Cannot Refund by Credit Card"),
                             tr("<p>The application cannot refund this "
                                "transaction using a credit card."));
        return;
    }

    int     ccardid = -1;
    double  total   =  0.0;
    double  tax     =  0.0;
    double  freight =  0.0;
    double  duty    =  0.0;
    int     currid  = -1;
    bool    taxexempt = false;
    QString docnum;
    QString refnum;
    int     ccpayid = -1;

    q.prepare("SELECT cmhead_id "
              "FROM cmhead "
              "WHERE (cmhead_number=:cmheadnumber);");
    q.bindValue(":cmheadnumber", _aropenCM->currentItem()->text(1));
    q.exec();
    if (q.first())
    {
        ParameterList ccp;
        ccp.append("cmhead_id", q.value("cmhead_id"));
        MetaSQLQuery ccm = mqlLoad(":/so/creditMemoCreditCard.mql");
        XSqlQuery ccq = ccm.toQuery(ccp);
        if (ccq.first())
        {
            ccardid = ccq.value("ccard_id").toInt();
            total   = ccq.value("total").toDouble();
            tax     = ccq.value("tax_in_cmcurr").toDouble();
            taxexempt = ccq.value("cmhead_tax_id").isNull();
            freight = ccq.value("cmhead_freight").toDouble();
            currid  = ccq.value("cmhead_curr_id").toInt();
            docnum  = ccq.value("cmhead_number").toString();
            refnum  = ccq.value("cohead_number").toString();
            ccpayid = ccq.value("ccpay_id").toInt();
        }
        else if (ccq.lastError().type() != QSqlError::None)
        {
            systemError(this, ccq.lastError().databaseText(), __FILE__, __LINE__);
            return;
        }
        else
        {
            QMessageBox::critical(this, tr("Credit Card Processing Error"),
                                  tr("Could not find a Credit Card to use for "
                                     "this Credit transaction."));
            return;
        }
    }
    else if (q.lastError().type() != QSqlError::None)
    {
        systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
        return;
    }
    else // cmhead not found - maybe it's just an open item
    {
        q.prepare("SELECT ccard_id, aropen_amount - aropen_paid AS balance,"
                  "       aropen_curr_id, aropen_docnumber "
                  "FROM aropen, ccard "
                  "WHERE ((aropen_cust_id=ccard_cust_id)"
                  "  AND  (ccard_active)"
                  "  AND  (aropen_open)"
                  "  AND  (aropen_id=:aropenid));");
        q.bindValue(":aropenid", _aropenCM->id());
        q.exec();

        if (q.first())
        {
            ccardid = q.value("ccard_id").toInt();
            total   = q.value("balance").toDouble();
            currid  = q.value("aropen_curr_id").toInt();
            docnum  = q.value("aropen_docnumber").toString();
        }
        else if (q.lastError().type() != QSqlError::None)
        {
            systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
            return;
        }
        else
        {
            QMessageBox::critical(this, tr("Credit Card Processing Error"),
                                  tr("Could not find a Credit Card to use for "
                                     "this Credit transaction."));
            return;
        }
    }

    CreditCardProcessor *cardproc = CreditCardProcessor::getProcessor();
    if (! cardproc)
        QMessageBox::critical(this, tr("Credit Card Processing Error"),
                              CreditCardProcessor::errorMsg());
    else
    {
        int refid = _aropenCM->id();
        int returnVal = cardproc->credit(ccardid, -2, total, tax, taxexempt,
                                         freight, duty, currid,
                                         docnum, refnum, ccpayid, "aropen", refid);
        if (returnVal < 0)
            QMessageBox::critical(this, tr("Credit Card Processing Error"),
                                  cardproc->errorMsg());
        else if (returnVal > 0)
            QMessageBox::warning(this, tr("Credit Card Processing Warning"),
                                 cardproc->errorMsg());
        else if (! cardproc->errorMsg().isEmpty())
            QMessageBox::information(this, tr("Credit Card Processing Note"),
                                     cardproc->errorMsg());
    }

    sFillList();
}
Exemple #2
0
void openSalesOrders::sDelete()
{
  if ( QMessageBox::warning(this, tr("Delete Sales Order?"),
                            tr("<p>Are you sure that you want to completely "
			       "delete the selected Sales Order?"),
			    QMessageBox::Yes,
			    QMessageBox::No | QMessageBox::Default) == QMessageBox::Yes)
  {
    q.prepare("SELECT deleteSo(:sohead_id) AS result;");
    q.bindValue(":sohead_id", _so->id());
    q.exec();
    if (q.first())
    {
      bool closeInstead = false;
      int result = q.value("result").toInt();
      if (result == -4 && _privleges->check("ProcessCreditCards"))
      {
	if ( QMessageBox::question(this, tr("Cannot Delete Sales Order"),
				   storedProcErrorLookup("deleteSo", result) + 
				   "<br>Would you like to refund the amount "
				   "charged and close the Sales Order instead?",
				   QMessageBox::Yes | QMessageBox::Default,
				   QMessageBox::No) == QMessageBox::Yes)
	{
	  CreditCardProcessor *cardproc = CreditCardProcessor::getProcessor();
	  if (! cardproc)
	    QMessageBox::critical(this, tr("Credit Card Processing Error"),
				  CreditCardProcessor::errorMsg());
	  else
	  {
	    XSqlQuery ccq;
	    ccq.prepare("SELECT ccpay_ccard_id, ccpay_curr_id,"
			"       SUM(ccpay_amount     * sense) AS amount,"
			"       SUM(ccpay_r_tax      * sense) AS tax,"
			"       SUM(ccpay_r_shipping * sense) AS freight "
			"FROM (SELECT ccpay_ccard_id, ccpay_curr_id, "
			"             CASE WHEN ccpay_status = 'C' THEN  1"
			"                  WHEN ccpay_status = 'R' THEN -1"
			"             END AS sense,"
			"             ccpay_amount,"
			"             COALESCE(ccpay_r_tax::NUMERIC, 0) AS ccpay_r_tax,"
			"             COALESCE(ccpay_r_shipping::NUMERIC, 0) AS ccpay_r_shipping "
			"      FROM ccpay, payco "
			"      WHERE ((ccpay_id=payco_ccpay_id)"
			"        AND  (ccpay_status IN ('C', 'R'))"
			"        AND  (payco_cohead_id=:coheadid)) "
			"      ) AS dummy "
			"GROUP BY ccpay_ccard_id, ccpay_curr_id;");
	    ccq.bindValue(":coheadid", _so->id());
	    ccq.exec();
	    if (ccq.first())
	    do
	    {
	      QString docnum = _so->currentItem()->text(0);
	      QString refnum = docnum;
	      int ccpayid = -1;
	      int coheadid = _so->id();
	      int returnVal = cardproc->credit(ccq.value("ccpay_ccard_id").toInt(),
					       -2,
					       ccq.value("amount").toDouble(),
					       ccq.value("tax").toDouble(),
					       true,
					       ccq.value("freight").toDouble(),
					       0,
					       ccq.value("ccpay_curr_id").toInt(),
					       docnum, refnum, ccpayid,
					       "cohead", coheadid);
	      if (returnVal < 0)
	      {
		QMessageBox::critical(this, tr("Credit Card Processing Error"),
				      cardproc->errorMsg());
		return;
	      }
	      else if (returnVal > 0)
	      {
		QMessageBox::warning(this, tr("Credit Card Processing Warning"),
				     cardproc->errorMsg());
		closeInstead = true;
	      }
	      else if (! cardproc->errorMsg().isEmpty())
	      {
		QMessageBox::information(this, tr("Credit Card Processing Note"),
				     cardproc->errorMsg());
		closeInstead = true;
	      }
	    } while (ccq.next());
	    else if (ccq.lastError().type() != QSqlError::None)
	    {
	      systemError(this, ccq.lastError().databaseText(),
			  __FILE__, __LINE__);
	      return;
	    }
	    else
	    {
	      systemError(this, tr("Could not find the ccpay records!"),
			  __FILE__, __LINE__);
	      return;
	    }

	  }
	}
      }
      else if (result == -1 || result == -5)
      {
	if ( QMessageBox::question(this, tr("Cannot Delete Sales Order"),
				   storedProcErrorLookup("deleteSo", result) + 
				   "<br>Would you like to Close the selected "
				   "Sales Order instead?",
				   QMessageBox::Yes | QMessageBox::Default,
				   QMessageBox::No) == QMessageBox::Yes)
	  closeInstead = true;
      }
      else if (result < 0)
      {
	systemError(this, storedProcErrorLookup("deleteSo", result),
		    __FILE__, __LINE__);
	return;
      }

      if (closeInstead)
      {
	q.prepare( "UPDATE coitem "
		   "SET coitem_status='C' "
		   "WHERE ((coitem_status <> 'X')"
		   "  AND  (coitem_cohead_id=:sohead_id));" );
	q.bindValue(":sohead_id", _so->id());
	q.exec();
	if (q.lastError().type() != QSqlError::None)
	{
	  systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
	  return;
	}
      }

      omfgThis->sSalesOrdersUpdated(-1);
      omfgThis->sProjectsUpdated(-1);
    }
    else if (q.lastError().type() != QSqlError::None)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
}
Exemple #3
0
void returnAuthorizationWorkbench::sProcess()
{
  if (!checkSitePrivs(_radue->id()))
    return;
  
  bool _post = ((_radue->altId() > 1) ||
		(_radue->altId() == 1 && _postmemos->isChecked())) ;

  q.prepare("SELECT createRaCreditMemo(:rahead_id,:post) AS result;");
  q.bindValue(":rahead_id",_radue->id());
  q.bindValue(":post",QVariant(_post));
  q.exec();
  if (q.first())
  {
    int cmheadid = q.value("result").toInt();
    if (cmheadid < 0)
    {
      systemError(this, storedProcErrorLookup("createRaCreditMemo", cmheadid), __FILE__, __LINE__);
      return;
    }
    q.prepare( "SELECT cmhead_number "
               "FROM cmhead "
               "WHERE (cmhead_id=:cmhead_id);" );
    q.bindValue(":cmhead_id", cmheadid);
    q.exec();
    if (q.first())
    {
      QMessageBox::information( this, tr("New Credit Memo Created"),
                                tr("<p>A new CreditMemo has been created and "
				                   "assigned #%1")
                                   .arg(q.value("cmhead_number").toString()));
	  if (_printmemo->isChecked())
	  {
		ParameterList params;
		params.append("cmhead_id", cmheadid);
		if (_post)
		  params.append("posted");

		printCreditMemo newdlg(this, "", TRUE);
		newdlg.set(params);
		newdlg.exec();
	  }
      if (_radue->altId() == 2)
      {
        ParameterList params;
        params.append("cmhead_id", cmheadid);

        returnAuthCheck newdlg(this, "", TRUE);
        newdlg.set(params);
        if (newdlg.exec() != XDialog::Rejected)
          sFillListDue();
      }
      else if (_radue->altId() == 3)
      {
	ParameterList ccp;
	ccp.append("cmhead_id", cmheadid);
  MetaSQLQuery ccm = mqlLoad("creditMemoCreditCards", "detail");
	XSqlQuery ccq = ccm.toQuery(ccp);
	if (ccq.first())
	{
	  int ccpayid = ccq.value("ccpay_id").toInt();
	  CreditCardProcessor *cardproc = CreditCardProcessor::getProcessor();
	  if (! cardproc)
	    QMessageBox::critical(this, tr("Credit Card Processing Error"),
				  CreditCardProcessor::errorMsg());
	  else if (! cardproc->errorMsg().isEmpty())
	    QMessageBox::critical(this, tr("Credit Card Processing Warning"),
				 cardproc->errorMsg());
	  else
	  {
	    QString docnum = q.value("cmhead_number").toString();
	    QString refnum = ccq.value("cohead_number").toString();
	    int refid = -1;
	    int returnValue = cardproc->credit(ccq.value("ccard_id").toInt(),
					 -2,
					 ccq.value("total").toDouble(),
					 ccq.value("tax_in_cmcurr").toDouble(),
					 ccq.value("cmhead_tax_id").isNull(),
					 ccq.value("cmhead_freight").toDouble(),
					 0,
					 ccq.value("cmhead_curr_id").toInt(),
					 docnum, refnum, ccpayid,
					 QString(), refid);
	    if (returnValue < 0)
	      QMessageBox::critical(this, tr("Credit Card Processing Error"),
				    cardproc->errorMsg());
	    else if (returnValue > 0)
	      QMessageBox::warning(this, tr("Credit Card Processing Warning"),
				   cardproc->errorMsg());
	    else if (! cardproc->errorMsg().isEmpty())
	      QMessageBox::information(this, tr("Credit Card Processing Note"),
				   cardproc->errorMsg());
	  }
	  // requery regardless 'cause the new credit memo means nothing's "due"
	  sFillListDue();
	}
	else if (ccq.lastError().type() != QSqlError::NoError)
	{
	  systemError(this, ccq.lastError().databaseText(), __FILE__, __LINE__);
	  return;
	}
	else
	{
	  QMessageBox::critical(this, tr("Credit Card Processing Error"),
				tr("Could not find a Credit Card to use for "
				   "this Credit transaction."));
	  sFillListDue();
	  return;
	}
      }
      else
	sFillListDue();
    }
    else if (q.lastError().type() != QSqlError::NoError)
    {
      systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
      return;
    }
  }
  else if (q.lastError().type() != QSqlError::NoError)
  {
    systemError(this, q.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
}
Exemple #4
0
void dspAROpenItems::sCCRefundCM()
{
  XSqlQuery dspCCRefundCM;
  if (list()->id("ccard_number") < 0)
  {
    QMessageBox::warning(this, tr("Cannot Refund by Credit Card"),
			 tr("<p>The application cannot refund this "
			    "transaction using a credit card."));
    return;
  }
  
  int     ccardid = -1;
  double  total   =  0.0;
  double  tax     =  0.0;
  double  freight =  0.0;
  double  duty    =  0.0;
  int     currid  = -1;
  bool    taxexempt = false;
  QString docnum;
  QString refnum;
  int     ccpayid = list()->currentItem()->id("ccard_number");

  dspCCRefundCM.prepare("SELECT ccpay_ccard_id, aropen_amount - aropen_paid AS balance, "
	    "       aropen_curr_id, aropen_docnumber "
            "FROM aropen "
            "     JOIN payaropen ON (aropen_id=payaropen_aropen_id) "
            "     JOIN ccpay ON (payaropen_ccpay_id=ccpay_id) "
            "WHERE ((aropen_id=:aropen_id)"
            "  AND  (ccpay_id=:ccpay_id));");
  dspCCRefundCM.bindValue(":aropen_id", list()->id());
  dspCCRefundCM.bindValue(":ccpay_id",  ccpayid);
  dspCCRefundCM.exec();
  if (dspCCRefundCM.first())
  {
    ccardid = dspCCRefundCM.value("ccpay_ccard_id").toInt();
    total   = dspCCRefundCM.value("balance").toDouble();
    currid  = dspCCRefundCM.value("aropen_curr_id").toInt();
    docnum  = dspCCRefundCM.value("aropen_docnumber").toString();
  }
  else if (dspCCRefundCM.lastError().type() != QSqlError::NoError)
  {
    systemError(this, dspCCRefundCM.lastError().databaseText(), __FILE__, __LINE__);
    return;
  }
  else
  {
    QMessageBox::critical(this, tr("Credit Card Processing Error"),
                          tr("Could not find a Credit Card to use for "
                             "this Credit transaction."));
    return;
  }

  CreditCardProcessor *cardproc = CreditCardProcessor::getProcessor();
  if (! cardproc)
    QMessageBox::critical(this, tr("Credit Card Processing Error"),
			  CreditCardProcessor::errorMsg());
  else
  {
    int refid = list()->id();
    int returnVal = cardproc->credit(ccardid, "-2", total, tax, taxexempt,
				     freight, duty, currid,
				     docnum, refnum, ccpayid, "aropen", refid);
    if (returnVal < 0)
      QMessageBox::critical(this, tr("Credit Card Processing Error"),
			    cardproc->errorMsg());
    else if (returnVal > 0)
      QMessageBox::warning(this, tr("Credit Card Processing Warning"),
			   cardproc->errorMsg());
    else if (! cardproc->errorMsg().isEmpty())
      QMessageBox::information(this, tr("Credit Card Processing Note"),
			   cardproc->errorMsg());
  }

  sFillList();
}