00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ocTypes.h"
00010 #include "rep_base.hpp"
00011
00012
00013
00014
00015
00016
00017
00018 class commissions_report: public rep_base
00019 {
00020 double total;
00021 double commission;
00022 string filter;
00023 public:
00024 commissions_report(ostream&sc, const cgiTemplates & in):rep_base(sc),total(0),commission(0)
00025 {
00026 copyTemplates(in);
00027 topKey = "reptop";
00028 endKey = "repend";
00029 }
00030 ~commissions_report(){;}
00031
00032 void setFilter( string filterVal ){ filter=filterVal; }
00033 bool run( llong AffiliateId, string Name )
00034 {
00035 total = 0;
00036 commission = 0;
00037 ocString sql =
00038 "select odr.Id as 'Order Id', "
00039 "odr.Order_Total as 'Order Total', "
00040 "prm.Percent_Commission as 'Commission', "
00041 "date_format(odr.Order_Date, '%m/%d/%Y') as 'Date Ordered', "
00042 "ost.Name as 'Order Status' "
00043 "from Ordered as odr "
00044 "inner join Promotion as prm on odr.Promotion = prm.Id "
00045 "inner Join Affiliate aff on aff.Promotion = prm.Id "
00046 "inner join Order_Status ost on ost.Id = Order_Status_Id "
00047 "left join Commission_Check_Orders cco on cco.Ordered = odr.Id "
00048 "where aff.Id = ";
00049 sql.append( AffiliateId );
00050 if( filter.length() )
00051 {
00052 sql += " and ";
00053 sql += filter;
00054 }
00055 sql += " order by odr.Order_Date desc limit 500";
00056
00057
00058 emitTop( Name );
00059 emitHeadings("Order Id|Order Total|Commission|Date Ordered|Order Status");
00060
00061 if ( getData( sql ) )
00062 {
00063 emitData();
00064 emitEnd();
00065 }
00066
00067 emitEnd();
00068
00069 }
00070 virtual void sendField( int iField, ocString & td )
00071 {
00072 money lineAmount;
00073 money lineCommission;
00074
00075 switch( iField )
00076 {
00077 case 1:
00078 lineAmount = atof(rs.getField(iField).format().c_str());
00079 webIO << part(dataKey).replace( "$data$", lineAmount.format("%n") );
00080 total += lineAmount.amount();
00081 break;
00082 case 2:
00083 lineAmount = atof(rs.getField(1).format().c_str());
00084 lineCommission.amount() = atof(rs.getField(iField).format().c_str());
00085 lineCommission.amount() *= lineAmount.amount();
00086 lineCommission.amount() /= 100.0;
00087 commission += lineCommission.amount();
00088 webIO << part(dataKey).replace( "$data$", lineCommission.format("%n") );
00089 break;
00090 default:
00091 webIO << part(dataKey).replace( "$data$", rs.getField(iField).format().c_str() );
00092 break;
00093 }
00094
00095 }
00096
00097 void derived_complete_event( void )
00098 {
00099 money totalAmount = total;
00100 money totalCommission = commission;
00101 webIO << part(rowKey);
00102 ocString totalText = "Total: ";
00103 webIO << part(dataKey).replace( "$data$", totalText );
00104 webIO << part(dataKey).replace( "$data$", totalAmount.format("%n") );
00105 webIO << part(dataKey).replace( "$data$", totalCommission.format("%n") );
00106 for( int pos=3; pos < rs.getFieldCount(); pos ++ )
00107 webIO << part(dataKey).replace( "$data$"," ");
00108
00109 webIO << part(endRowKey);
00110 }
00111 };